1. SpringBoot 的作用
简化 xml(除外 mybatis)
独立的应用程序
单独的 war 工程 - 不需要集成 tomcat 插件运行
1.创建独立的 Spring 应用程序
2.嵌入的 Tomcat,无需部署 WAR 文件
3.简化 Maven 配置
4.自动配置 Spring
5.土工生产就绪型功能,如指标,健康检查和外部配置
6.开箱即用,没有代码生成,也无需 XML 配置
2. SpringBoot 注解
@RestController == Controller 每个方法上加上@ResponseBody
@ResponseBody 返回 所有请求方法返回 json 格式。
@Value("${name}") 取出在配置文件中的数据
@ComponentScan(basePackages={"com.bkrn.user.controller","com.bkrn.user.service"}) 组
件扫描,可自动发现和装配一些 Bean。
@MapperScan(basePackages="com.bkrn.user.dao") //扫描 dao 包
@EnableAutoConfiguration
//运行注解
@ControllerAdvice 全局异常拦截器类上用的注解
@ExceptionHandler(RuntimeException.class) //捕获所有的运行异常
3. 在项目中配置 pom.xml(注意项目路径问题)
4.
5.
6.
7.
4.0.0
com.li
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
springboot-helloworld
0.0.1-SNAPSHOT
war
org.springframework.boot
spring-boot-starter-parent
1.3.3.RELEASE
赖即可 -->
org.springframework.boot
spring-boot-starter-freemarker
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.1.1
mysql
mysql-connector-java
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
org.apache.maven.plugins
maven-compiler-plugin
1.8
1.8
org.springframework.boot
spring-boot-maven-plugin
com.bkrn.App
repackage
4 项目运行类
@ComponentScan(basePackages={"com.bkrn.user.controller","com.bkrn.use
r.service"}) //组件扫描,可自动发现和装配一些Bean。
@MapperScan(basePackages="com.bkrn.user.dao")
@EnableAutoConfiguration //运行注解
public class App {
//扫描dao 包
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
5 使用 freemarker
在 resources 目录下建 templates 文件夹存放 ftl 格式文件
6 配属多个环境
在 application.properties 里面配置 spring.profiles.active=prd
配置两个不同的 properties 分别是 application-prd.properties
application-pre.properties
想用哪一个直接在 application.properties 里面配置 spring.profiles.active=prd
7 静态文件
静态文件放在 resources 目录下 static 文件夹里 默认加载 static 文件夹里
8 打包部署
war 打包成 war 包
在 pom.xml 中 有
在本地安装 Maven
打开 cmd
进入 到项目中 F:\Word\Eclipse\workspace\springboot-helloworld
输入 mvn clean
mvn package 打包
进入到项目中 target 文件中
清除项目中 target 文件