广告
返回顶部
首页 > 资讯 > 后端开发 > Python >IDEA插件之mybatisx 插件使用教程
  • 478
分享到

IDEA插件之mybatisx 插件使用教程

2024-04-02 19:04:59 478人浏览 薄情痞子

Python 官方文档:入门教程 => 点击学习

摘要

目录mybatisx 插件使用插件安装自动生成代码文件跳转代码自动补全自定义模板MybatisX 是一款基于 idea 的快速开发插件,为效率而生。今天给大家介绍下mybatisx

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

mybatisx 插件使用

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

插件安装

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

mybatisx 功能:

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

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

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

自动生成代码

连接数据源

mybatisx-generator 自动生成代码

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

查看自动生成的代码

文件跳转

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

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

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

代码自动补全

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

generate mybatis sql

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>

自动补全操作示例

自定义模板

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

.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;

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;

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;

@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>

模版文件恢复为默认设置

到此这篇关于mybatisx 插件使用的文章就介绍到这了,更多相关mybatisx 插件使用内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: IDEA插件之mybatisx 插件使用教程

本文链接: https://www.lsjlt.com/news/147850.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作