b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

SpringBoot2.X (二十六):SpringBoot整合 MybatisPlus + MySQL CURD 示例

电脑杂谈  发布时间:2019-08-28 10:01:36  来源:网络整理

boot x有什么用_boot(x:)可以删除吗_one x刷boot

本文链接:

maven3.5.3
SpringBoot 2.1.2.RELEASE
Hikari DataSource
mybatis-plus 3.0.7.1

开始之前先放张项目

在这里插入图片描述

     <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>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.0.7.1</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
spring:
  application:
    name: mybatis-plus-curd
  datasource:
    username: root
    password: root
    url: jdbc:mysql://localhost:3306/test?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&autoReconnect=true
    driver-class-name: com.mysql.cj.jdbc.Driver
    type: com.zaxxer.hikari.HikariDataSource
    # hikari 连接池  https://blog.csdn.net/X5fnncxzq4/article/details/80649679
    hikari:
      # 自动提交
      auto-commit: true
      connection-test-query: SELECT 1
      # 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生SQLException, 默认:30秒
      # 生产环境 connect-time 10 s
      connection-timeout: 9000
      # 一个连接idle状态的最大时长(毫秒),超时则被释放(retired),默认:10分钟
      idle-timeout: 600000
      # 一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),默认:30分钟 1800000ms,建议设置比超时时长少60秒,参考MySQL wait_timeout 7200s 参数(# 一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),默认:30分钟 1800000ms,建议设置比超时时长少60秒,参考MySQL wait_timeout参数(show variables like '%timeout%';) -->  ) -->
      max-lifetime: 1800000
      # 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
      maximum-pool-size: 15
      # 最小连接数
      minimum-idle: 10
      # 连接池名字
      pool-name: DemoHikariCP
mybatis-plus:
  # MyBaits 别名包扫描路径,通过该属性可以给包中的类注册别名
  type-aliases-package: com.fxbin.mybatisplus.bean.*
  # 该配置请和 typeAliasesPackage 一起使用,如果配置了该属性,则仅仅会扫描路径下以该类作为父类的域对象 。
  type-aliases-super-type: java.lang.Object
  configuration:
    # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    # 驼峰下划线转换
    map-underscore-to-camel-case: true
    # 配置的缓存的全局开关
    cache-enabled: true
    # 延时加载的开关
    lazy-loading-enabled: true
    # 开启的话,延时加载一个属性时会加载该对象全部属性,否则按需加载属性
    multiple-result-sets-enabled: true
    use-generated-keys: true
    default-statement-timeout: 60
    default-fetch-size: 100

boot(x:)可以删除吗_boot x有什么用_one x刷boot

package com.fxbin.mybatisplus.bean;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
 * User
 *
 * @author fxbin
 * @version v1.0
 * @since 2019/2/10 1:30
 */
@Data
public class User implements Serializable {
    /**
     * 主键ID, ID自增
     */
    @TableId(type = IdType.AUTO)
    private Integer id;
    /**
     * 用户名
     */
    private String username;
    /**
     * 密码
     */
    private String password;
    /**
     * 创建时间
     */
    private Date gmtCreate;
    /**
     * 修改时间
     */
    private Date gmtModified;
}
package com.fxbin.mybatisplus.config;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
 * MybatisPlusConfig
 *
 * @author fxbin
 * @version v1.0
 * @since 2019/2/10 1:30
 */
@Configuration
@EnableTransactionManagement
public class MybatisPlusConfig {
    /**
     * 性能分析,不建议生产使用 用来观察 SQL 执行情况及执行时长, 默认dev,staging 环境开启
     * @author fxbin
     * @return com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
     */
    @Bean
    @Profile({"dev", "staging"})
    public PerformanceInterceptor performanceInterceptor(){
        //启用性能分析插件, SQL是否格式化 默认false,此处开启
        return new PerformanceInterceptor().setFormat(true);
    }
    /**
     * 分页插件
     * @author fxbin
     * @return com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
}


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-120832-1.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...