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
Top comments (0)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.