SpringBoot 整合Tk.mybatis Tk mybatis generator

编程入门 行业动态 更新时间:2024-10-09 10:24:43

SpringBoot 整合<a href=https://www.elefans.com/category/jswz/34/1761019.html style=Tk.mybatis Tk mybatis generator"/>

SpringBoot 整合Tk.mybatis Tk mybatis generator

   首先, pom不能引用mybatis-spring-boot-starter, 加入tk mybatis依赖:

<!-- .mybatis/mapper-spring-boot-starter --><dependency><groupId>tk.mybatis</groupId><artifactId>mapper-spring-boot-starter</artifactId><version>2.1.5</version></dependency><!-- .mybatis/mapper --><dependency><groupId>tk.mybatis</groupId><artifactId>mapper</artifactId><version>4.1.5</version></dependency>

第二, 在启动类application.java那里, import的MapperScan改为import tk.mybatis.spring.annotation.MapperScan;

第三, mapper改为这种泛型的风格 : public interface TaUserMapper extends Mapper<TaUser> { }

 

而在pom.xml里面配置插件

<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><plugin><groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-maven-plugin</artifactId><version>1.3.6</version><configuration><configurationFile>${basedir}/src/main/resources/tk-mybatis-autogen.xml</configurationFile><!--允许移动生成的文件 --><verbose>true</verbose><overwrite>true</overwrite></configuration><dependencies><dependency><groupId>tk.mybatis</groupId><artifactId>mapper</artifactId><version>4.1.5</version></dependency></dependencies></plugin></plugins></build>

 

在resource下建立tk-mybatis-autogen.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE generatorConfiguration PUBLIC"-//mybatis//DTD MyBatis Generator Configuration 1.0//EN"".dtd" >
<generatorConfiguration><classPathEntry location="C:\Users\dgmislrh\.m2\repository\org\postgresql\postgresql\42.2.5\postgresql-42.2.5.jar"/><!--如果你希望不生成和Example查询有关的内容,那么可以按照如下进行配置: targetRuntime="MyBatis3Simple"--><context id="context" targetRuntime="MyBatis3Simple"><plugin type="tk.mybatis.mapper.generator.MapperPlugin"><property name="mappers" value="tk.mybatis.mappermon.Mapper"/><property name="caseSensitive" value="true"/></plugin><commentGenerator><!--是否去除生成的自动注解(英文的) true是去除 false 不去除--><property name="suppressAllComments" value="true"/><!-- 是否去除自动生成的日期 true:是 : false:否 --><property name="suppressDate" value="true"/></commentGenerator><jdbcConnection userId="postgres" password="xxxx" driverClass="org.postgresql.Driver" connectionURL="jdbc:postgresql://xxxx:5432/xxxdb"/><!--true:使用BigDecimal对应DECIMAL和 NUMERIC数据类型false:默认,scale>0;length>18:使用BigDecimal;scale=0;length[10,18]:使用Long;scale=0;length[5,9]:使用Integer;scale=0;length<5:使用Short;--><!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL和 NUMERIC 类型解析为java.math.BigDecimal --><javaTypeResolver><property name="forceBigDecimals" value="false"/></javaTypeResolver><!-- !!!! Model Configurations !!!! --><!--生成POJO类的位置--><javaModelGenerator targetPackage="com.xxmon.modules.system.entity" targetProject="src/main/java"><property name="enableSubPackages" value="false"/><!-- 从数据库返回的值被清理前后的空格 --><property name="trimStrings" value="true"/></javaModelGenerator><!-- !!!! Mapper XML Configurations !!!! --><!--生成映射文件xml的位置--><sqlMapGenerator targetPackage="mappings.modules.ta" targetProject="src/main/resources"><property name="enableSubPackages" value="false"/></sqlMapGenerator><!-- !!!! Mapper Interface Configurations !!!! --><!--mapper.xml  接口生成的位置--><javaClientGenerator targetPackage="com.xxxmon.modules.system.dao" type="XMLMAPPER" targetProject="src/main/java"><property name="enableSubPackages" value="false"/></javaClientGenerator><!--schema即为数据库名, tableName为数据库中的对应的数据库表名或视图名, domainObjectName是要生成的实体类名,如果想要mapper配置文件加入sql的where条件查询, 可以将enableCountByExample等设为true,这样就会生成一个对应domainObjectName的Example类, enableCountByExample等设为false时,就不会生成对应的Example类了.table其他属性:enableCountByExample="false"enableUpdateByExample="false"enableDeleteByExample="false"enableSelectByExample="false"selectByExampleQueryId="false"如果table里边不配置property,默认字段都生成为类属性。<ignoreColumn column="FRED" />//忽略字段<columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" />//无论字段是什么类型,生成的类属性都是varchar。--><!-- !!!! Table Configurations !!!! --><!-- 下面这个是生成该数据库下的所有的数据表的 --><table schema="public" tableName="tc_user_access" enableCountByExample="false" enableDeleteByExample="false"enableSelectByExample="false" enableUpdateByExample="false"/></context>
</generatorConfiguration>

展开maven, 运行generator.

 

 

 

 

更多推荐

SpringBoot 整合Tk.mybatis Tk mybatis generator

本文发布于:2024-02-13 22:19:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1761030.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Tk   SpringBoot   generator   mybatis

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!