Springboot-mybatis-demoで出会った穴


文書ディレクトリ
  • 前言
  • 問題&解決
  • 1.初期化Mavenエンジニアリングが遅すぎる
  • 2.Spring Boot統合druidタイムゾーンの問題と接続タイムアウトの問題
  • 3.フルエンジニアリングダウンロード
  • 前言
    環境:
    java version "1.8.0_45"
    Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
    
    mysql Server version: 8.0.13
    
    Eclipse IDE Version: Photon Release (4.8.0)
    

    問題&解決
    1.初期化Maven工程が遅すぎる
    海外サイトを使って更新するのは時間がもったいないので、国内サイトがpomにあるように変更しました.xmlに追加(pom.xmlは依存関係を統合)
    <repositories>
    		<repository>
    			<id>alimavenid>
    			<name>aliyun mavenname>
    			<url>http://maven.aliyun.com/nexus/content/groups/public/url>
    		repository>
    		repositories>
    

    完全なpom.xmlは以下の通り
    
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    	<modelVersion>4.0.0modelVersion>
    
    	<groupId>com.wintergroupId>
    	<artifactId>springboot-mybatis-demoartifactId>
    	<version>0.0.1-SNAPSHOTversion>
    	<packaging>jarpackaging>
    
    	<name>springboot-mybatis-demoname>
    	<description>Demo project for Spring Bootdescription>
    
    	<parent>
    		<groupId>org.springframework.bootgroupId>
    		<artifactId>spring-boot-starter-parentartifactId>
    		<version>1.5.6.RELEASEversion>
    		<relativePath/> 
    	parent>
    	<repositories>
    		<repository>
    			<id>alimavenid>
    			<name>aliyun mavenname>
    			<url>http://maven.aliyun.com/nexus/content/groups/public/url>
    		repository>
    		repositories>
    
    	<properties>
    		<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
    		<project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>
    		<java.version>1.8java.version>
    	properties>
    
    	<dependencies>
    		<dependency>
    			<groupId>org.springframework.bootgroupId>
    			<artifactId>spring-boot-starter-jdbcartifactId>
    		dependency>
    		<dependency>
    			<groupId>org.mybatis.spring.bootgroupId>
    			<artifactId>mybatis-spring-boot-starterartifactId>
    			<version>1.3.0version>
    		dependency>
    		<dependency>
    			<groupId>org.springframework.bootgroupId>
    			<artifactId>spring-boot-starter-thymeleafartifactId>
    		dependency>
    		<dependency>
    			<groupId>org.springframework.bootgroupId>
    			<artifactId>spring-boot-starter-webartifactId>
    		dependency>
    
    		<dependency>
    			<groupId>org.springframework.bootgroupId>
    			<artifactId>spring-boot-starter-testartifactId>
    			<scope>testscope>
    		dependency>
    		<dependency>
    			<groupId>mysqlgroupId>
    			<artifactId>mysql-connector-javaartifactId>
    			<version>8.0.13version>
    		dependency>
    		
    		<dependency>
    			<groupId>com.alibabagroupId>
    			<artifactId>druidartifactId>
    			<version>1.0.11version>
    		dependency>
    		<dependency>
    			<groupId>com.fasterxml.jackson.coregroupId>
    			<artifactId>jackson-coreartifactId>
    		dependency>
    		<dependency>
    			<groupId>com.fasterxml.jackson.coregroupId>
    			<artifactId>jackson-databindartifactId>
    		dependency>
    		<dependency>
    			<groupId>com.fasterxml.jackson.datatypegroupId>
    			<artifactId>jackson-datatype-jodaartifactId>
    		dependency>
    		<dependency>
    			<groupId>com.fasterxml.jackson.modulegroupId>
    			<artifactId>jackson-module-parameter-namesartifactId>
    		dependency>
    		
    		<dependency>
    			<groupId>com.github.pagehelpergroupId>
    			<artifactId>pagehelper-spring-boot-starterartifactId>
    			<version>1.1.2version>
    		dependency>
    		
    		<dependency>
    			<groupId>com.alibabagroupId>
    			<artifactId>druid-spring-boot-starterartifactId>
    			<version>1.1.0version>
    		dependency>
    		
    		<dependency>
    			<groupId>net.sf.mpxjgroupId>
    			<artifactId>mpxjartifactId>
    			<version>7.1.0version>
    		dependency>
    
    		
    		<dependency>
    			<groupId>org.springframework.bootgroupId>
    			<artifactId>spring-boot-starter-loggingartifactId>
    		dependency>
    		
    		<dependency>
    			<groupId>org.projectlombokgroupId>
    			<artifactId>lombokartifactId>
    		dependency>
    	dependencies>
    
    	<build>
    		<plugins>
    			<plugin>
    				<groupId>org.springframework.bootgroupId>
    				<artifactId>spring-boot-maven-pluginartifactId>
    			plugin>
    			
    			<plugin>
    				<groupId>org.mybatis.generatorgroupId>
    				<artifactId>mybatis-generator-maven-pluginartifactId>
    				<version>1.3.2version>
    				<configuration>
    					<configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xmlconfigurationFile>
    					<overwrite>trueoverwrite>
    					<verbose>trueverbose>
    				configuration>
    			plugin>
    		plugins>
    	build>
    
    
    project>
    
    

    2.Spring Boot統合druidタイムゾーンの問題と接続タイムアウトの問題&serverTimezone=GMT%2B8&autoReconnect=trueの完全なアプリケーションを追加します.ymlは以下の通り
    server:
      port: 8080
    
    spring:
        datasource:
            name: test
            url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8&autoReconnect=true&failOverReadOnly=false&allowMultiQueries=true 
            username: root
            password: root
            #   druid   
            type: com.alibaba.druid.pool.DruidDataSource
            driver-class-name: com.mysql.cj.jdbc.Driver
            filters: stat
            maxActive: 20
            initialSize: 1
            maxWait: 60000
            minIdle: 1
            timeBetweenEvictionRunsMillis: 60000
            minEvictableIdleTimeMillis: 300000
            validationQuery: select 'x'
            testWhileIdle: true
            testOnBorrow: false
            testOnReturn: false
            poolPreparedStatements: true
            maxOpenPreparedStatements: 20
    mybatis:
      mapper-locations: classpath:mapping/*.xml
      type-aliases-package: com.winter.model
    
    #pagehelper
    pagehelper:
        helperDialect: mysql
        reasonable: true
        supportMethodsArguments: true
        params: count=countSql
    

    3.完全なプロジェクトのダウンロード
    Chasssser CSDN