Quotes Generator
1.controller
package com.example.demo.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import com.example.demo.service.quoteservice;
@Controller
public class QuotesController
{
@Autowired
private quoteservice quoteService;
@GetMapping("/")
public String show_Quotes_Page(Model model)
{
String quote = quoteService.send_quote();
model.addAttribute("quo", quote);
return "quotes";
}
}
2.Service
package com.example.demo.service;
import java.util.List;
import java.util.Random;
import org.springframework.stereotype.Service;
@Service
public class quoteservice
{
public String send_quote()
{
List<String> quotesList = List.of
("Failure is Stepping Stone of Success",
"Hardwork never fails",
"Love is Life",
"I ride my soul",
"Talent never fails");
Random random = new Random();
int random_no = random.nextInt(quotesList.size());
return quotesList.get(random_no);
}
}
3.html.file
<!DOCTYPE>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title> Random Quote Generator </title>
<style>
</style>
</head>
<body>
<div>
<form action="/" method="get">
<h2> Random Quote Generator </h2>
<h3 th:text = "${quo}"> </h3>
<button type="submit"> Next Quote </button>
</form>
</div>
</body>
</html>
Top comments (5)
epd implement panni pakrathu bro
spring.io/tools
Thank you 👍
java,html,springboot ellathayum epd connect panninga
Using spring boot we can connect java and html
Platform -springtoolsuite4