MyBatis自动生成Mapper插件,配置完可根据自动生成Dao接口、xml文件、实体类。可满足大部分sql需求
生成的Dao接口效果public interface MessageMapper {
int deleteByPrimaryKey(Integer id);
int selectCountByMap(Map map);
Message selectByMap(Map map);
List selectListByMap(Map 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);
}
使用教程
1.将mybatis-generator-kecikeci.jar和mysql-connector-java-5.1.42.jar放到资源文件目录resources下
2.pom.xml文件中配置插件
${project.basedir}/src/main/kotlin
${project.basedir}/src/test/kotlin
org.springframework.boot
spring-boot-maven-plugin
org.mybatis.generator
mybatis-generator-maven-plugin
1.3.5
com.kecikeci
mybatis-generator-kecikeci
1.0
system
${project.basedir}/src/main/resources/mybatis-generator-kecikeci.jar
3.新建generatorConfig.xml配置,需pom.xml中先引入mybatis的包<?xml version="1.0" encoding="UTF-8" ?>
/p>
"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
connectionURL="jdbc:mysql://127.0.0.1:3306/springboot4kt?characterEncoding=utf-8"
userId="root" password="root" />
tableName="message"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
name="useActualColumnNames"
value="true" />
将其中的包名、数据库链接、表名,改成自己的
4.配置Maven生成器mybatis-generator:generate -e
源码已开源,基础代码是引用的别人的,致敬!我添加了selectListByMap和selectByMap,去除了些没用的代码。
觉得好用,请点星~