IDEA插件之mybatisx 插件使用教程

2023-01-21 0 2,932

目录

MybatisX 是一款基于 IDEA 的快速开发插件,为效率而生。今天给大家介绍下mybatisx 插件使用。

mybatisx 插件使用

官网:https://baomidou.com/pages/ba5b24

插件安装

file ==> preferences ==> plugins:搜索mybatisx,安装插件

IDEA插件之mybatisx 插件使用教程

mybatisx 功能:

文件跳转:点击图标,可实现mapper接口、对应xml之间的互相跳转,serverImpl层跳转到注入的mapper接口

代码自动生成:根据表自动生成实体类、mapper接口、mapper xml、service、serverImpl类,模板自定义

mapper方法自动填充:mapper接口中输入部分方法名,可自动补全代码,并在对应的mapper xml中生成sql语句

自动生成代码

连接数据源

IDEA插件之mybatisx 插件使用教程

IDEA插件之mybatisx 插件使用教程

mybatisx-generator 自动生成代码

IDEA插件之mybatisx 插件使用教程

IDEA插件之mybatisx 插件使用教程

IDEA插件之mybatisx 插件使用教程

说明:实体类的包名、类名,moduler path、base path、package name均可手动编辑

查看自动生成的代码

IDEA插件之mybatisx 插件使用教程

文件跳转

mapper接口:点击图标,跳转mapper xml文件

IDEA插件之mybatisx 插件使用教程

mapper xml:点击图标,跳转到mapper接口

IDEA插件之mybatisx 插件使用教程

PersonServiceImpl:点击图标,跳转到mapper接口

IDEA插件之mybatisx 插件使用教程

代码自动补全

mapper 接口写出方法名 ==> 右击 ==> show context actions

IDEA插件之mybatisx 插件使用教程

generate mybatis sql

IDEA插件之mybatisx 插件使用教程

mapper xml生成的sql

<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE mapper
        PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\"
        \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\">
<mapper namespace=\"com.example.demo.mapper.PersonMapper\">
    <resultMap id=\"BaseResultMap\" type=\"com.example.demo.pojo.Person\">
            <id property=\"id\" column=\"id\" jdbcType=\"INTEGER\"/>
            <result property=\"name\" column=\"name\" jdbcType=\"VARCHAR\"/>
            <result property=\"age\" column=\"age\" jdbcType=\"INTEGER\"/>
    </resultMap>
    <sql id=\"Base_Column_List\">
        id,name,age
    </sql>
    <!-- mapper xml自动生成的sql语句 -->
    <select id=\"selectAllByName\" resultMap=\"BaseResultMap\">
        select
        <include refid=\"Base_Column_List\"/>
        from person
        where
        name = #{name,jdbcType=VARCHAR}
    </select>
</mapper>

自动补全操作示例

IDEA插件之mybatisx 插件使用教程

自定义模板

mybatisx 模板:可对模板(ftl)进行修改、并恢复默认设置

IDEA插件之mybatisx 插件使用教程

.meta.xml

<?xml version=\"1.0\" encoding=\"utf-8\" ?>
<templates>
    <template>
        <property name=\"configName\" value=\"serviceInterface\"/>
        <property name=\"configFile\" value=\"serviceInterface.ftl\"/>
        <property name=\"fileName\" value=\"${domain.fileName}Service\"/>
        <property name=\"suffix\" value=\".java\"/>
        <property name=\"packageName\" value=\"${domain.basePackage}.service\"/>
        <property name=\"encoding\" value=\"${domain.encoding}\"/>
        <property name=\"basePath\" value=\"${domain.basePath}\"/>
    </template>
    <template>
        <property name=\"configName\" value=\"serviceImpl\"/>
        <property name=\"configFile\" value=\"serviceImpl.ftl\"/>
        <property name=\"fileName\" value=\"${domain.fileName}ServiceImpl\"/>
        <property name=\"suffix\" value=\".java\"/>
        <property name=\"packageName\" value=\"${domain.basePackage}.service.impl\"/>
        <property name=\"encoding\" value=\"${domain.encoding}\"/>
        <property name=\"basePath\" value=\"${domain.basePath}\"/>
    </template>
    <template>
        <property name=\"configName\" value=\"mapperInterface\"/>
        <property name=\"configFile\" value=\"mapperInterface.ftl\"/>
        <property name=\"fileName\" value=\"${domain.fileName}Mapper\"/>
        <property name=\"suffix\" value=\".java\"/>
        <property name=\"packageName\" value=\"${domain.basePackage}.mapper\"/>
        <property name=\"encoding\" value=\"${domain.encoding}\"/>
        <property name=\"basePath\" value=\"${domain.basePath}\"/>
    </template>
    <template>
        <property name=\"configName\" value=\"mapperXml\"/>
        <property name=\"configFile\" value=\"mapperXml.ftl\"/>
        <property name=\"fileName\" value=\"${domain.fileName}Mapper\"/>
        <property name=\"suffix\" value=\".xml\"/>
        <property name=\"packageName\" value=\"mapper\"/>
        <property name=\"encoding\" value=\"${domain.encoding}\"/>
        <property name=\"basePath\" value=\"src/main/resources\"/>
    </template>
</templates>

mapperInterface.ftl

package ${mapperInterface.packageName};
import ${tableClass.fullClassName};
<#if tableClass.pkFields??>
    <#list tableClass.pkFields as field><#assign pkName>${field.shortTypeName}</#assign></#list>
</#if>
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author ${author!}
* @createDate ${.now?string(\'yyyy-MM-dd HH:mm:ss\')}
*/
public interface ${mapperInterface.fileName} extends BaseMapper<${tableClass.shortClassName}> {
}

serviceInterface.ftl

package ${baseInfo.packageName};
import ${tableClass.fullClassName};
<#if baseService??&&baseService!=\"\">
import ${baseService};
    <#list baseService?split(\".\") as simpleName>
        <#if !simpleName_has_next>
            <#assign serviceSimpleName>${simpleName}</#assign>
        </#if>
    </#list>
</#if>
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @author ${author!}
* @description 针对表【${tableClass.tableName}<#if tableClass.remark?has_content>(${tableClass.remark!})</#if>】的数据库操作Service
* @createDate ${.now?string(\'yyyy-MM-dd HH:mm:ss\')}
*/
public interface ${baseInfo.fileName} extends IService<${tableClass.shortClassName}> {
}

serviceImpl.ftl

package ${baseInfo.packageName};
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import ${tableClass.fullClassName};
import ${serviceInterface.packageName}.${serviceInterface.fileName};
import ${mapperInterface.packageName}.${mapperInterface.fileName};
<#if baseService??&&baseService!=\"\">
import ${baseService};
    <#list baseService?split(\".\") as simpleName>
        <#if !simpleName_has_next>
            <#assign serviceSimpleName>${simpleName}</#assign>
        </#if>
    </#list>
</#if>
import org.springframework.stereotype.Service;
/**
* @author ${author!}
* @description 针对表【${tableClass.tableName}<#if tableClass.remark?has_content>(${tableClass.remark!})</#if>】的数据库操作Service实现
* @createDate ${.now?string(\'yyyy-MM-dd HH:mm:ss\')}
*/
@Service
public class ${baseInfo.fileName} extends ServiceImpl<${mapperInterface.fileName}, ${tableClass.shortClassName}>
    implements ${serviceInterface.fileName}{
}

mapperXml.ftl

<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE mapper
        PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\"
        \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\">
<mapper namespace=\"${mapperInterface.packageName}.${baseInfo.fileName}\">
    <resultMap id=\"BaseResultMap\" type=\"${tableClass.fullClassName}\">
        <#list tableClass.pkFields as field>
            <id property=\"${field.fieldName}\" column=\"${field.columnName}\" jdbcType=\"${field.jdbcType}\"/>
        </#list>
        <#list tableClass.baseFields as field>
            <result property=\"${field.fieldName}\" column=\"${field.columnName}\" jdbcType=\"${field.jdbcType}\"/>
        </#list>
    </resultMap>
    <sql id=\"Base_Column_List\">
        <#list tableClass.allFields as field>${field.columnName}<#sep>,<#if field_index%3==2>${\"\\n        \"}</#if></#list>
    </sql>
</mapper>

模版文件恢复为默认设置

IDEA插件之mybatisx 插件使用教程

:本文采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可, 转载请附上原文出处链接。
1、本站提供的源码不保证资源的完整性以及安全性,不附带任何技术服务!
2、本站提供的模板、软件工具等其他资源,均不包含技术服务,请大家谅解!
3、本站提供的资源仅供下载者参考学习,请勿用于任何商业用途,请24小时内删除!
4、如需商用,请购买正版,由于未及时购买正版发生的侵权行为,与本站无关。
5、本站部分资源存放于百度网盘或其他网盘中,请提前注册好百度网盘账号,下载安装百度网盘客户端或其他网盘客户端进行下载;
6、本站部分资源文件是经压缩后的,请下载后安装解压软件,推荐使用WinRAR和7-Zip解压软件。
7、如果本站提供的资源侵犯到了您的权益,请邮件联系: 442469558@qq.com 进行处理!

猪小侠源码-最新源码下载平台 Java教程 IDEA插件之mybatisx 插件使用教程 http://www.20zxx.cn/463580/xuexijiaocheng/javajc.html

猪小侠源码,优质资源分享网

常见问题
  • 本站所有资源版权均属于原作者所有,均只能用于参考学习,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担
查看详情
  • 最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,建议提前注册好百度网盘账号,使用百度网盘客户端下载
查看详情

相关文章

官方客服团队

为您解决烦忧 - 24小时在线 专业服务