Project Overview:
This is a simple Spring Boot web application that allows users to pick a color from the URL and view a background rendered in that color dynamically using Thymeleaf template rendering.
Technologies Used:
- Spring Boot (Java)
- Thymeleaf
- HTML/CSS
- Maven
Code
ColourPickerApplication.java`
java
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ColourPickerApplication {
public static void main(String[] args) {
SpringApplication.run(ColourPickerApplication.class, args);
}
}
ColourController.java`
java
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 ColourController {
@GetMapping("/")
public String getColorPicker(@RequestParam(defaultValue = "#123456") String color, Model model) {
model.addAttribute("selectedcolor", color);
return "color";
}
}
color.html` (in `src/main/resources/templates/`)
html
<!DOCTYPE html>
Color Picker
<br> body {<br> margin: 0;<br> height: 100vh;<br> display: flex;<br> justify-content: center;<br> align-items: center;<br> flex-direction: column;<br> font-family: Arial, sans-serif;<br> }<br> h2 {<br> color: white;<br> text-shadow: 1px 1px 2px black;<br> }<br>
Selected Color:
Before:

After :

Source :
GitLab Repository: https://gitlab.com/payligam/springboot/-/tree/main/ColourPicker?ref_type=heads
Credits:
Developer: Sudhakar
Mentorship: Mr. Muthuramalingam (Mentor)
Top comments (0)