1.集成freemarker
-1 添加freemarker依赖
org.springframework.boot spring-boot-starter-freemarker
-2 在application中添加配置
############################################################ # # freemarker # ############################################################ #\u8bbe\u5b9aftl\u6587\u4ef6\u8def\u5f84 spring.freemarker.template-loader-path=classpath:/templates spring.freemarker.cache=false spring.freemarker.charset=UTF-8 spring.freemarker.check-template-location=true spring.freemarker.content-type=text/html spring.freemarker.expose-request-attributes=true spring.freemarker.expose-session-attributes=true spring.freemarker.request-context-attribute=request spring.freemarkerr.suffix=.ftl
1.集成thymeleaf
-1添加依赖
org.springframework.boot spring-boot-starter-thymeleaf
-2 application 配置
############################################################ # # thymeleaf \u9759\u6001\u8d44\u6e90\u914d\u7f6e # ############################################################ spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.suffix=.html spring.thymeleaf.mode=HTML5 spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.servlet.content-type=text/html # \u5173\u95ed\u7f13\u5b58, \u5373\u65f6\u5237\u65b0, \u4e0a\u7ebf\u751f\u4ea7\u73af\u5883\u9700\u8981\u6539\u4e3atrue spring.thymeleaf.cache=false
3. 热部署集成
- 1.添加依赖
org.springframework.boot spring-boot-devtools true
- 2.application配置
#devtools是否启动 spring.devtools.restart.enabled=true #devtools监听的目录 spring.devtools.restart.additional-paths=src/main/java
如果前端资源太多的话会影响热部署的速度,可以排除对静态文件的监听
#spring.devtools.restart.exclude=static/**,public/**
#spring.devtools.restart.exclude=WEB-INF/**
4.springBoot整合mybaties
首先添加基本的公共配置
使用generatorConfig生成mapper和pojo
实现基于mybaties的CRUD功能
整合mybaties-pagehelper实现分页
自定义mapper实现
注意在springboot中常常使用classpath,这个classpath指代的是resource目录下哦!!1
4-1 使用generatorConfig生成mapper和pojo
4-1-1在generatorConfig.xml中要指定要生成pojo类,mapper,java映射的目录位置以及table名字!
运行原理:在指定了table后,当程序运行时就会面向对象生成
4-1-2
创建了GeneratorDisplay.java来指定generatorConfig.xml
5.springboot集成log ,便于打印sql 语句
通过添加log4j.properties,修改日志的级别为debug
log4j.rootLogger=DEBUG,console,dailyFile # TODO \u53d1\u5e03\u5230\u963f\u91cc\u4e91\u8bb0\u5f97\u6dfb\u52a0\uff0c\u53e6\u5916\u63a7\u5236\u53f0\u4e0d\u8f93\u51fa(\u53ea\u8f93\u51fawarn\u6216\u8005error\u4fe1\u606f) #INFO,console,dailyFile log4j.logger.org.mybatis = DEBUG log4j.logger.com.imooc.mapper=DEBUG log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.encoding=UTF-8 log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%l] - [%p] %m%n # \u5b9a\u671f\u6eda\u52a8\u65e5\u5fd7\u6587\u4ef6\uff0c\u6bcf\u5929\u90fd\u4f1a\u751f\u6210\u65e5\u5fd7 log4j.appender.dailyFile=org.apache.log4j.DailyRollingFileAppender log4j.appender.dailyFile.encoding=UTF-8 log4j.appender.dailyFile.Threshold=INFO # TODO \u672c\u5730\u65e5\u5fd7\u5730\u5740\uff0c\u6b63\u5f0f\u73af\u5883\u8bf7\u52a1\u5fc5\u5207\u6362\u4e3a\u963f\u91cc\u4e91\u5730\u5740 log4j.appender.dailyFile.File=C:/logs/imooc/log.log4j #log4j.appender.dailyFile.File=/imooc/logs/log.log4j log4j.appender.dailyFile.DatePattern='.'yyyy-MM-dd log4j.appender.dailyFile.layout=org.apache.log4j.PatternLayout log4j.appender.dailyFile.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%l] - [%p] %m%n