1:@RestController
表示该类中所有方法返回json格式 @Controller+@ResponseBody。是Spring4.0提供的。
2:Springboot启动原理
SpringMVC注解方式启动,内置HTTP服务器(默认Tomcat)。
3:@EnableAutoConfiguration
作用:扫包范围,默认在当前类里。
4:@ComponentScan
配置扫包范围,如:@ComponentScan("com.zhaoy.controller")
5:@SpringBootApplication
等于@EnableAutoConfiguration+@ComponentScan同级包和当前包
6:报错(No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?)
使用jre运行而不是jdk,需要修改为jdk运行。
7:配置文件不生效(application.yml)
需要放在resources/config/目录下,并注意配置文件内容格式。
8:SpringBoot整合freemarker
pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
application.yml:
spring:
freemarker.tempalte-loader-path: classpath:/templates
freemarker.cache: false
freemarker.charset: UTF-8
freemarker.check-template-location: true
freemarker.content-type: text/html
freemarker.expose-request-attributes: true
freemarker.expose-session-attributes: true
freemarker.request-context-attribute: request
freemarker.suffix: .ftl
9:SpringBoot整合JSP
pom.xml:
<!--添加tomcat依赖模块.-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<!-- 使用jsp引擎,springboot内置tomcat没有此依赖 -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
打包方式更改为:war