IDEA插件之mybatisx?插件使用教程
MybatisX 是一款基于 IDEA 的快速開發(fā)插件,為效率而生。今天給大家介紹下mybatisx 插件使用。
mybatisx 插件使用
官網(wǎng):https://baomidou.com/pages/ba5b24
插件安裝
file ==> preferences ==> plugins:搜索mybatisx,安裝插件
mybatisx 功能:
文件跳轉(zhuǎn):點擊圖標(biāo),可實現(xiàn)mapper接口、對應(yīng)xml之間的互相跳轉(zhuǎn),serverImpl層跳轉(zhuǎn)到注入的mapper接口
代碼自動生成:根據(jù)表自動生成實體類、mapper接口、mapper xml、service、serverImpl類,模板可自定義
mapper方法自動填充:mapper接口中輸入部分方法名,可自動補(bǔ)全代碼,并在對應(yīng)的mapper xml中生成sql語句
自動生成代碼
連接數(shù)據(jù)源
mybatisx-generator 自動生成代碼
說明:實體類的包名、類名,moduler path、base path、package name均可手動編輯
查看自動生成的代碼
文件跳轉(zhuǎn)
mapper接口:點擊圖標(biāo),跳轉(zhuǎn)mapper xml文件
mapper xml:點擊圖標(biāo),跳轉(zhuǎn)到mapper接口
PersonServiceImpl:點擊圖標(biāo),跳轉(zhuǎn)到mapper接口
代碼自動補(bǔ)全
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>
自動補(bǔ)全操作示例
自定義模板
mybatisx 模板:可對模板(ftl)進(jìn)行修改、并恢復(fù)默認(rèn)設(shè)置
.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>】的數(shù)據(jù)庫操作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>】的數(shù)據(jù)庫操作Service實現(xiàn) * @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>
模版文件恢復(fù)為默認(rèn)設(shè)置
到此這篇關(guān)于mybatisx 插件使用的文章就介紹到這了,更多相關(guān)mybatisx 插件使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
關(guān)于Nacos配置管理的統(tǒng)一配置管理、自動刷新詳解
這篇文章主要介紹了關(guān)于Nacos配置管理的統(tǒng)一配置管理、自動刷新詳解,Nacos是阿里的一個開源產(chǎn)品,是針對微服務(wù)架構(gòu)中的服務(wù)發(fā)現(xiàn)、配置管理、服務(wù)治理的綜合型解決方案,需要的朋友可以參考下2023-05-05@Valid注解的作用及@Valid注解與@Validated的區(qū)別
這篇文章主要介紹了@Valid注解的作用及@Valid注解與@Validated的區(qū)別,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08JSON的String字符串與Java的List列表對象的相互轉(zhuǎn)換
這篇文章主要介紹了JSON的String字符串與Java的List列表對象的相互轉(zhuǎn)換,如果在瀏覽器端JSON是list則轉(zhuǎn)為string結(jié)構(gòu)來處理,需要的朋友可以參考下2016-04-04Springboot項目對數(shù)據(jù)庫用戶名密碼實現(xiàn)加密過程解析
這篇文章主要介紹了Springboot項目對數(shù)據(jù)庫用戶名密碼實現(xiàn)加密過程解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-06-06