This content originally appeared on DEV Community and was authored by V I N O T H
1) File --> New --> Spring Starter Project
2) Name --> Calculator
3) Select Maven as Type
4) Click Next
5) Add Dependencies: DevTools, Web, Thymeleaf
6) Click Next, Finish
7) Go to src/main/java --> Create a package called com.example.demo.controller
8) Now, right click the newly created package.
package com.example.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class Color_controller {
@GetMapping("/")
public String change_color(@RequestParam(defaultValue = "blue") String colors, Model model)
{
model.addAttribute("selectedColor", colors);
return "color";
}
}
<!DOCTYPE html>
<html xmlns:th="http://www.thymelear.org">
<head>
<title> Color Picker </title>
</head>
<body th:style="'background-color:' + ${selectedColor}">
<form action="/" method="get">
<input type="color" th:value='${selectedColor}' name="colors">
<input type="submit" value="Change Color">
</form>
</body>
</html>
OUTPUT
This content originally appeared on DEV Community and was authored by V I N O T H
V I N O T H | Sciencx (2025-04-15T17:35:10+00:00) background color change using spring boot mini project. Retrieved from https://www.scien.cx/2025/04/15/background-color-change-using-spring-boot-mini-project/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.
