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";
}
}
Color Picker
Enter fullscreen mode
Exit fullscreen mode
OUTPUT