java常用、通用代码或配置
pom.xml
支持springBoot
parent
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.1</version> </parent>
starter
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency>
支持springWeb
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
支持mybatis【TODO】
<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <!--不知道为什么,去了版本就不支持MapperScan注解--> <version>1.3.0</version> </dependency> <!-- mysql 数据库驱动. --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency>
支持aop
<!-- SpringBoot 拦截器 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency>
properties或者yml常用配置
服务端口
server:
port: 2525
视图前后缀配置
spring:
mvc:
view:
prefix: /WEB-INF/views
suffix: .jsp
数据库yml【todo】
spring:
datasource:
# 使用druid数据源
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/test21.2.27?serverTimezone=UTC
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
filters: stat
maxActive: 20
initialSize: 1
maxWait: 60000
minIdle: 1
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: select 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxOpenPreparedStatements: 20