上一篇完成了后端数据库,映射和Service 的构建,本篇来完成前端部分。
前端部使用于SpringMVC为MVC框架,使用ThymeLeaf,首先在pom中增加依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
增加完毕后进行Maven Project Update,应该注意到,所有新增的依赖都没有指定版本,Spring会自动进行版本适配。
本系列重点不是前端,所以前端采用一个单一页面,页面上有一个表格,表格中罗列所有的Person信息,可以直接在表格中修改后保存,也可以删除和增加联系人。
第一步先实现控制器,本文控制器只需要CURD四个接口,控制器比较简单,就直接和Application类写在一起,源码如下:
package com.springBoot.curdDemo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com