SpringBoot搭建
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
1.添加parent依赖
2.添加dependency依赖
3.创建App,并且创建主函数,添加SpringBootApplication注解,使用SpringApplication.run(App.class,args)
来启动SpringBoot
项目结构
1.springboot包
2.其他controller,pojo都在springboot包下
3.pojo要使用 @Component
@ConfigurationProperties(prefix=“person”)
@PropertySource(value={“classpath:person.properties”})
注解,并配置yml或properties文件
4.工厂类:@Configuration、@Bean
进行注入的三种方式
1.application.properties/application.yml全局配置文件配置,使用@ConfigurationProperties(prefix=“xxxx”)注解
2.使用xxxx.properties/xxxx.yml配置文件,使用@PropertySource(value={“classpath:xxxx.properties”})注解
3.使用java工厂模型,使用@Configuration、@Bean注解
多profile
spring.profiles.active=prod/dev
application-prod.properties
application-dev.properties
yml多文档块
引入jquery
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.3.1-2</version>
</dependency>
静态资源
在resource文件下添加static文件夹
添加mybatis依赖
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>
数据库配置
spring:
datasource:
username: root
password: wy981116
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/student
mybatis:
config-location: classpath:config/mybatis/SqlMapConfig.xml
mapper-location: classpath:config/mapper/*.xml