Spring Boot 中使用Thymeleaf

引入依赖

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>


JPA( Java Persistence API) 资源库,就是为 POJO (Plain Ordinary Java Object)提供持久化的标准规范,然后将 POJO 通过 ORM(Object-Relational Mapping)持久化到数据库中。


配置文件

spring:
thymeleaf:
mode: HTML5
encoding: UTF-8
content-type: text/html
cache: false

新建控制器


这个实体用来与数据库中的表建立映射关系


注解

作用

@Table

指定关联的数据库的表名

@Id

唯一标识

@GeneratedValue

自动生成

@Entity

表明这是一个实体类,如果表名和实体类名相同的话,@Table可以省略

映射

Java中的对象:

@Controller
public class HelloController {

private Logger logger = LoggerFactory.getLogger(HelloController.class);
/**
* 测试hello
* @return
*/
@RequestMapping(value = "/hello",method = RequestMethod.GET)
public String hello(Model model) {
model.addAttribute("name", "Dear");
return "hello";
}
}