网站首页 > 技术文章 正文
mybatis-generator-kecikeci
MyBatis自动生成Mapper插件,配置完可根据自动生成Dao接口、xml文件、实体类。可满足大部分sql需求
Java
生成的Dao接口效果
public interface MessageMapper { int deleteByPrimaryKey(Integer id); int selectCountByMap(Map<Object, Object> map); Message selectByMap(Map<Object, Object> map); List<Message> selectListByMap(Map<Object, Object> map); int insert(Message record); int insertSelective(Message record); Message selectByPrimaryKey(Integer id); int updateByPrimaryKeySelective(Message record); int updateByPrimaryKeyWithBLOBs(Message record); int updateByPrimaryKey(Message record); }
使用教程
将mybatis-generator-kecikeci.jar和mysql-connector-java-5.1.42.jar放到资源文件目录resources下
pom.xml文件中配置插件
<build> <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory> <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory> <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.5</version> <dependencies> <dependency> <groupId>com.kecikeci</groupId> <artifactId>mybatis-generator-kecikeci</artifactId> <version>1.0</version> <scope>system</scope> <systemPath>${project.basedir}/src/main/resources/mybatis-generator-kecikeci.jar</systemPath> </dependency> </dependencies> </plugin> </plugins></build>
Java
3.新建generatorConfig.xml配置,需pom.xml中先引入mybatis的包
<?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="src/main/resources/mysql-connector-java-5.1.42.jar" /> <context id="context1" targetRuntime="MyBatis3"> <property name="beginningDelimiter" value=""/> <property name="endingDelimiter" value=""/> <!-- 为生成的Java模型创建一个toString方法 --> <plugin type="org.mybatis.generator.plugins.ToStringPlugin"></plugin> <!-- 自定义的序列化 类文件 插件 --> <plugin type="com.kecikeci.mybatis.generator.plugin.SerializablePlugin"></plugin> <!-- 取消 Example 类文件的生成,在进行代码生成器的过程中,生成 selectCountByMap selectListByMap 两种方法,代替 Example 方法的生成 --> <plugin type="com.kecikeci.mybatis.generator.plugin.SelectCountAndListByMapPlugin"></plugin> <!-- 自定义注释部分(实体类entity生成过程中,将配置的数据库部分的注释部分生成,关键节点的注解部分生成) --> <plugin type="com.kecikeci.mybatis.generator.plugin.MyTableAnnotationPlugin"></plugin> <!-- 自定义 注释部分,增加字段方面的注释 --> <commentGenerator type="com.kecikeci.mybatis.generator.plugin.MyCommentGeneratorPlugin"> <property name="suppressAllComments" value="true" /> </commentGenerator> <!-- 数据库连接URL,用户名,密码 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/springboot4kt?characterEncoding=utf-8" userId="root" password="root" /> <javaModelGenerator targetPackage="me.forxx.springboot4kt.model" targetProject="src/main/Kotlin" /> <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources" /> <javaClientGenerator targetPackage="me.forxx.springboot4kt.dao" targetProject="src/main/Kotlin" type="XMLMAPPER" /> <!--生成对应表及类名--> <table tableName="message" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> <property name="useActualColumnNames" value="true" /> <!-- 需要插入时返回主键值,请将此属性打开,column值为主键的列明 <generatedKey column="taskId" sqlStatement="MySql" identity="true" /> --> </table> </context></generatorConfiguration>
将其中的包名、数据库链接、表名,改成自己的
4.配置Maven生成器
mybatis-generator:generate -e
Java
猜你喜欢
- 2024-09-29 MybatisPlus—kotlin代码生成 mybatisplus 代码生成器
- 2024-09-29 Spring boot Mybatis 整合 springboot整合mybatis流程
- 2024-09-29 SpringBoot使用Mybatis-FreeMarker
- 2024-09-29 增强Mybatis常用方案 mybatis-plus扩展
- 2024-09-29 网易架构师吐血整理:2分钟看完Mybatis核心知识点
- 2024-09-29 Mybatis的XML映射文件的继承问题 mybatis映射文件的主要元素及作用
- 2024-09-29 Mybatis 自动生成bean mybatis 自动生成bo
- 2024-09-29 深入理解Python生成器(Generators)
- 2024-09-29 如何避免出现 SQL 注入漏洞 怎样避免sql注入
- 2024-09-29 代码生成插件支持eclipse,IntelliJ Idea
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- oraclesql优化 (66)
- 类的加载机制 (75)
- feignclient (62)
- 一致性hash算法 (71)
- dockfile (66)
- 锁机制 (57)
- javaresponse (60)
- 查看hive版本 (59)
- phpworkerman (57)
- spark算子 (58)
- vue双向绑定的原理 (68)
- springbootget请求 (58)
- docker网络三种模式 (67)
- spring控制反转 (71)
- data:image/jpeg (69)
- base64 (69)
- java分页 (64)
- kibanadocker (60)
- qabstracttablemodel (62)
- java生成pdf文件 (69)
- deletelater (62)
- com.aspose.words (58)
- android.mk (62)
- qopengl (73)
- epoch_millis (61)
本文暂时没有评论,来添加一个吧(●'◡'●)