• Springboot整合tk-mybatis


    
    
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.29</version>
    </dependency>

    <dependency>
    <groupId>tk.mybatis</groupId>
    <artifactId>mapper-spring-boot-starter</artifactId>
    <version>2.1.5</version>
    </dependency>
    <plugin>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-maven-plugin</artifactId>
    <version>1.3.6</version>
    <configuration>
    <configurationFile>
    ${basedir}/src/main/resources/generator/generatorConfig.xml
    </configurationFile>
    <overwrite>true</overwrite>
    <verbose>true</verbose>
    </configuration>
    <dependencies>
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.29</version>
    </dependency>
    <dependency>
    <groupId>tk.mybatis</groupId>
    <artifactId>mapper</artifactId>
    <version>4.0.0</version>
    </dependency>
    </dependencies>
    </plugin>
    《可不加》
    <dependencyManagement>
    <dependencies>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>2.1.6.RELEASE</version>
    <type>pom</type>
    <scope>import</scope>
    </dependency>
    </dependencies>
    </dependencyManagement>
    《可不加》
    
    
    /*启动类扫描mybatis的通用接口*/
    import tk.mybatis.spring.annotation.MapperScan;
    @MapperScan("com.itmuch.mapper")

    配置mysql 版本<5.X
    spring:
    # mysql
    datasource:
    url: jdbc:mysql://127.0.0.1:3306/数据库?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
    driver-class-name: com.mysql.jdbc.Driver
    hikari:
    username: root
    password: root

        config.properties内容

    jdbc.driverClass=com.mysql.jdbc.Driver
    jdbc.url=jdbc:mysql://127.0.0.1:3306/user_center?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
    jdbc.user=root
    jdbc.password=root
    #模块名称
    modelName=user
    #表名
    tableName=user

    generatorConfig.xml内容
    <!DOCTYPE generatorConfiguration
    PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
    "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

    <generatorConfiguration>
    <properties resource="generator/config.properties"/>

    <context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">
    <property name="beginningDelimiter" value="`"/>
    <property name="endingDelimiter" value="`"/>

    <plugin type="tk.mybatis.mapper.generator.MapperPlugin">
    <property name="mappers" value="tk.mybatis.mapper.common.Mapper"/>
    <property name="caseSensitive" value="true"/>
    </plugin>

    <jdbcConnection driverClass="${jdbc.driverClass}"
    connectionURL="${jdbc.url}"
    userId="${jdbc.user}"
    password="${jdbc.password}">
    </jdbcConnection>

    <!--实体-->
    <javaModelGenerator targetPackage="com.itmuch.entity.${modelName}"
    targetProject="src/main/java"/>
    <!--mapper-->
    <sqlMapGenerator targetPackage="com.itmuch.mapper.${modelName}"
    targetProject="src/main/resources"/>
    <!--mapper接口-->
    <javaClientGenerator targetPackage="com.itmuch.mapper.${modelName}"
    targetProject="src/main/java"
    type="XMLMAPPER"/>

    <table tableName="${tableName}">
    <generatedKey column="id" sqlStatement="JDBC"/>
    </table>
    </context>
    </generatorConfiguration>



  • 相关阅读:
    蓝桥网试题 java 基础练习 特殊的数字
    蓝桥网试题 java 基础练习 杨辉三角形
    蓝桥网试题 java 基础练习 查找整数
    蓝桥网试题 java 基础练习 数列特征
    蓝桥网试题 java 基础练习 字母图形
    蓝桥网试题 java 基础练习 01字串
    蓝桥网试题 java 基础练习 回文数
    蓝桥网试题 java 基础练习 特殊回文数
    Using text search in Web page with Sikuli
    each of which 用法
  • 原文地址:https://www.cnblogs.com/jiahaoJAVA/p/13057484.html
Copyright © 2020-2023  润新知