spring boot集成mybatis

来源:互联网 发布:淘宝模板是什么意思 编辑:程序博客网 时间:2024/06/16 00:22
application.yml
server:  port: 8088spring:    datasource:        name: test        url: jdbc:mysql://127.0.0.1:3306/test        username: root        password: root        # 使用druid数据源        type: com.alibaba.druid.pool.DruidDataSource        driver-class-name: com.mysql.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: 20mybatis:  mapper-locations: classpath:mapping/*.xml  type-aliases-package: com.example1.demo1.model#pagehelper分页插件pagehelper:    helperDialect: mysql    reasonable: true    supportMethodsArguments: true    params: count=countSql

generatorConfig.xml
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE generatorConfiguration        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"><generatorConfiguration>    <!-- 数据库驱动:选择你的本地硬盘上面的数据库驱动包-->    <classPathEntry  location="F:\tools\mybatis-generator-core-1.3.5\lib\mysql-connector-java-5.1.26-bin.jar"/>    <context id="DB2Tables"  targetRuntime="MyBatis3">        <commentGenerator>            <property name="suppressDate" value="true"/>            <!-- 是否去除自动生成的注释 true:是 : false:否 -->            <property name="suppressAllComments" value="true"/>        </commentGenerator>        <!--数据库链接URL,用户名、密码 -->        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1/test" userId="root" password="root">        </jdbcConnection>        <javaTypeResolver>            <property name="forceBigDecimals" value="false"/>        </javaTypeResolver>        <!-- 生成模型的包名和位置-->        <javaModelGenerator targetPackage="main.java.com.example1.demo1.model" targetProject="src">            <property name="enableSubPackages" value="true"/>            <property name="trimStrings" value="true"/>        </javaModelGenerator>        <!-- 生成映射文件的包名和位置-->        <sqlMapGenerator targetPackage="main.resources.mapping" targetProject="src">            <property name="enableSubPackages" value="true"/>        </sqlMapGenerator>        <!-- 生成DAO的包名和位置-->        <javaClientGenerator type="XMLMAPPER" targetPackage="main.java.com.example1.demo1.mapper" targetProject="src">            <property name="enableSubPackages" value="true"/>        </javaClientGenerator>        <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->        <table tableName="users" domainObjectName="Users" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>    </context></generatorConfiguration>
b.点击run-Edit Configurations 
Maven  -> mybatis-gennerator:gennerator -e