常用依赖
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<!-- 打包时跳过测试-->
<skipTests>true</skipTests>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<!-- 作用域 -->
<scope>runtime</scope>
</dependency>
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3</version>
</dependency>
<!-- 测试 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<!-- 作用域 -->
<scope>test</scope>
</dependency>
<!-- 实体类使用@Data -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- swagger2测试-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!-- json工具-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.76</version>
</dependency>
</dependencies>
<build>
<!-- 打jar包插件 maven>双击package -->
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
常用配置
server:
port: 8888
servlet:
context-path: /stest #路径名
#应用名称
spring:
jeckson:
date-format: yyyy-MM-dd hh:mm:ss
time-zone: GTM+8 #后台返回前台时间处理 hh:mm:ss解决后台返回前台时间不一致
redis:
port: 63792
host: 127.0.0.1
password: 123456
application:
name: spider
datasource:
name: yinxun #数据库名
url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8&useSSL=false #假如时区报错,就增加一个时区配置?serverTimezone=UTC
username: root #用户名
password: 123456 #密码
driver-class-name: com.mysql.cj.jdbc.Driver #数据库链接驱动
#mybatis-plus
mybatis-plus:
mapper-locations: classpath:mapper/*.xml #配置映射文件 自定义时使用
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #日志打印
lucenePath: F:/tmp/lucene/ #别的地方可通过@Value取得
启动类
@EnableTransactionManagement//事务管理
@EnableScheduling//开启定时任务
@MapperScan("com.liulang.xx.mapper")//扫描包,也可以放在mybatis-plus 上
@SpringBootApplication
public class SssApp {
public static void main(String[] args) {
SpringApplication.run(SssApp.class,args);
}
}
mybatis-plus 使用
依赖(pom)
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3</version>
</dependency>
(application.yml)
#mybatis-plus
mybatis-plus:
mapper-locations: classpath:mapper/*