JAVA-3545: Move spring-thymeleaf-3 into spring-web-modules
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
package com.baeldung.thymeleaf;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package main.java.com.baeldung.thymeleaf.articles;
|
||||
|
||||
public class Article {
|
||||
|
||||
private String name;
|
||||
private String url;
|
||||
|
||||
public Article(String name, String url) {
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package main.java.com.baeldung.thymeleaf.articles;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/api/articles")
|
||||
public class ArticlesController {
|
||||
|
||||
@GetMapping
|
||||
public String allArticles(Model model) {
|
||||
model.addAttribute("articles", fetchArticles());
|
||||
return "articles/articles-list";
|
||||
}
|
||||
|
||||
private List<Article> fetchArticles() {
|
||||
return Arrays.asList(
|
||||
new Article(
|
||||
"Introduction to Using Thymeleaf in Spring",
|
||||
"https://www.baeldung.com/thymeleaf-in-spring-mvc"
|
||||
),
|
||||
new Article(
|
||||
"Spring Boot CRUD Application with Thymeleaf",
|
||||
"https://www.baeldung.com/spring-boot-crud-thymeleaf"
|
||||
),
|
||||
new Article(
|
||||
"Spring MVC Data and Thymeleaf",
|
||||
"https://www.baeldung.com/spring-mvc-thymeleaf-data"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.thymeleaf.blog;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@Controller
|
||||
public class BlogController {
|
||||
|
||||
@GetMapping("/blog/new")
|
||||
public String newBlogPost(Model model) {
|
||||
// Set a random ID so we can see it in the HTML form
|
||||
BlogDTO blog = new BlogDTO();
|
||||
blog.setBlogId(Math.abs(new Random().nextLong() % 1000000));
|
||||
|
||||
model.addAttribute("blog", blog);
|
||||
|
||||
return "blog/blog-new";
|
||||
}
|
||||
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package com.baeldung.thymeleaf.blog;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class BlogDTO {
|
||||
|
||||
private long blogId;
|
||||
|
||||
private String title;
|
||||
|
||||
private String body;
|
||||
|
||||
private String author;
|
||||
|
||||
private String category;
|
||||
|
||||
private Date publishedDate;
|
||||
|
||||
public long getBlogId() {
|
||||
return blogId;
|
||||
}
|
||||
|
||||
public void setBlogId(long blogId) {
|
||||
this.blogId = blogId;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody(String body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public void setCategory(String category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public Date getPublishedDate() {
|
||||
return publishedDate;
|
||||
}
|
||||
|
||||
public void setPublishedDate(Date publishedDate) {
|
||||
this.publishedDate = publishedDate;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.thymeleaf.conditionalclasses;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
public class ConditionalClassesController {
|
||||
|
||||
@GetMapping("/conditional-classes")
|
||||
public String getConditionalClassesPage( Model model) {
|
||||
model.addAttribute("condition", true);
|
||||
return "conditionalclasses/conditionalclasses";
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.baeldung.thymeleaf.cssandjs;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class CssAndJsApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CssAndJsApplication.class, args);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.thymeleaf.cssandjs;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
public class CssAndJsController {
|
||||
|
||||
@GetMapping("/styled-page")
|
||||
public String getStyledPage(Model model) {
|
||||
model.addAttribute("name", "Baeldung Reader");
|
||||
return "cssandjs/styledPage";
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.thymeleaf.currencies;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
@Controller
|
||||
public class CurrenciesController {
|
||||
|
||||
@GetMapping(value = "/currency")
|
||||
public String exchange(
|
||||
@RequestParam(value = "amount", required = false) String amount,
|
||||
@RequestParam(value = "amountList", required = false) List amountList,
|
||||
Locale locale) {
|
||||
|
||||
return "currencies/currencies";
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package com.baeldung.thymeleaf.option;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
*
|
||||
* Simple student POJO with few fields
|
||||
*
|
||||
*/
|
||||
public class Student implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -8582553475226281591L;
|
||||
|
||||
@NotNull(message = "Student ID is required.")
|
||||
@Min(value = 1000, message = "Student ID must be at least 4 digits.")
|
||||
private Integer id;
|
||||
|
||||
@NotNull(message = "Student name is required.")
|
||||
private String name;
|
||||
|
||||
@NotNull(message = "Student gender is required.")
|
||||
private Character gender;
|
||||
|
||||
private Float percentage;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Character getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public void setGender(Character gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
|
||||
public Float getPercentage() {
|
||||
return percentage;
|
||||
}
|
||||
|
||||
public void setPercentage(Float percentage) {
|
||||
this.percentage = percentage;
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.thymeleaf.option;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
|
||||
/**
|
||||
* Handles requests for the student model.
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class StudentController {
|
||||
|
||||
|
||||
@RequestMapping(value = "/student", method = RequestMethod.GET)
|
||||
public String addStudent(Model model) {
|
||||
model.addAttribute("student", new Student());
|
||||
return "option/studentForm.html";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user