springboot总结(一)

本文详细介绍了SpringBoot的常用配置、启动类、Mybatis-Plus的使用,包括依赖、配置类和各种操作。同时,文章还涵盖了Swagger测试、解决跨域问题、时间处理、WebMvc拦截器配置、定时任务实现、事务处理、JWT生成、全局返回结果、统一异常处理、MD5加密、Redis连接、JSON与对象转换以及如何接收不同类型的前端数据。
摘要由CSDN通过智能技术生成

常用依赖

 <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/*
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值