Spring Boot 之 使用Thymeleaf

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";
  }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章