SpringBoot 2.0 学习(四)之thymeleaf模板+CURD
学习一门新的技术,起码的CURD增删改查是必要的,所以自己也简单的用thymeleaf模板完成了增删改查的操作
如果前端页面代码发生更改,不想反复重启服务器,怎么办?
application.properties里面添加spring.thymeleaf.cache=false
SpringBoot+thymeleaf+JdbcTemplate增删改查
第一步:在pom.xml里面添加相关依赖
<!-- Spring JDBC 的依赖包 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- MYSQL依赖包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- 阿里巴巴druid数据源 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.12</version>
</dependency>
第二步:依次编写domain(此处省略)、Dao、Service、实现类、Controller类的编写
Dao层
service层
业务实现类
controller层
第三步:使用thymeleaf在src/main/resources/templates目录下listUser.html和saveOrUpdate.html
listUser.html的body部分
saveOrUpdate.html的body部分
第四步:运行项目,浏览器输入http://localhost:9090/user/showAllUser,如下即表示访问ok
显示所有
添加
修改