热部署
添加devtools就可以实现热部署,以前在springmvc时期,每次调整完代码都要重新运行才可以,说实话好烦的。
<!--devtools依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
只要你每次修改完代码,boot会重新帮你启动,省去了比较多的麻烦。
修改端口
springboot默认是8080端口,访问路径是/,那如果我们平时想修改怎么办。可以在application.properties或者yml文件中添加如下的东西。
#端口
server.port=80
#项目访问根路径(server.servlet.context-path过时了)
server.servlet.context-path=/
日志输出
SpringBoot默认的日志框架为logback,是log4j作者的做的新一代的日志框架,性能更好。
SpringBoot与Mybatis-plus整合
<!--MySQL驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--druid连接池-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
<!--mybatis-plus-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
yml配置中添加如下:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/stu_score
username: root
password: 123456
druid:
max-active: 20
min-idle: 10
initial-size: 5
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
默认支持驼峰配置。
Application启动类加@MapperScan(“com.gaby.boot.mapper”) 注解 以及yml配置中添加mapper.xml的路径
@SpringBootApplication
@ComponentScan(basePackages="com.gaby.boot")
@MapperScan("com.gaby.boot.mapper")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
mybatis-plus:
mapper-locations: ['classpath:com/gaby/boot/mapper/xml/*.xml']