springboot中的小技巧

1.Thymeleaf
在时使用Thymeleaf的时候不用设置html标签:在默认的Thymeleaf的页面中,对于.html的要求比较严格,少写或者多写标签,都会被报错,而在springboot 2.x版本中,只需要设置Thymeleaf的模板就可以解决这些问题:在application.propertie配置入下参数

spring.thymeleaf.cache=false
spring.thymeleaf.mode=LEGACYHTML5

2.自定义 Favicon
这个是默认启动的端口的logo,如果觉得这个logo不符合自己的个性,那么就可以修改:
首先需要在 application.propertie 中关闭原有的logo

spring.mvc.favicon.enable=false

在将自己的 favicon.ico 放到src/main/resources/static下 ,然后再重新启动项目就可以了。

3.初始化数据
使用 Jpa

在使用spring boot jpa的情况下设置spring.jpa.hibernate.ddl-auto的属性设置为 create or create-drop的时候,Spring Boot 启动时默认会扫描 classpath 下面(项目中一般是 resources 目录)是否有import.sql,如果有机会执行import.sql脚本。

使用 Spring JDBC

使用 Spring JDBC 需要在配置文件中添加以下配置

spring:
datasource:
schema: classpath:db/schema.sql
data: classpath:db/data.sql
sql-script-encoding: utf-8
jpa:
hibernate:
ddl-auto: none

schema :脚本中创建表的语句
data :脚本中初始化数据的预计
sql-script-encoding:设置脚本的编码
Spring Boot 项目启动的时候会自动执行脚本。

posted on 2019-09-03 13:37  xsDao  阅读(182)  评论(0)    收藏  举报