Skip to content

Instantly share code, notes, and snippets.

@JoJoJotarou
Last active December 19, 2023 17:45
Show Gist options
  • Save JoJoJotarou/e463ca00bed749800d95f269bf8cf4a7 to your computer and use it in GitHub Desktop.
Save JoJoJotarou/e463ca00bed749800d95f269bf8cf4a7 to your computer and use it in GitHub Desktop.
IDEA MybatisX template (1. 自定义 controller 模板 2. mapperInterface 添加 @Mapper 注解)
<?xml version="1.0" encoding="utf-8" ?>
<templates>
<!-- .meta.xml 添加自定义 controller 模板信息,其他不变 -->
<template>
<property name="configName" value="controller"/>
<property name="configFile" value="controller.ftl"/>
<property name="fileName" value="${domain.fileName}Controller"/>
<property name="suffix" value=".java"/>
<property name="packageName" value="${domain.basePackage}.controller"/>
<property name="encoding" value="${domain.encoding}"/>
<property name="basePath" value="${domain.basePath}"/>
</template>
</templates>
package ${baseInfo.packageName};
import ${serviceInterface.packageName}.${serviceInterface.fileName};
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* ${tableClass.tableName} 控制层。
*
* @author ${author!}
* @since ${.now?string('yyyy-MM-dd HH:mm:ss')}
*/
@RestController
@RequestMapping("/${tableClass.shortClassName?uncap_first}")
public class ${baseInfo.fileName} {
private final ${serviceInterface.fileName} ${serviceInterface.fileName?uncap_first};
public ${baseInfo.fileName} (${serviceInterface.fileName} ${serviceInterface.fileName?uncap_first}){
this.${serviceInterface.fileName?uncap_first} = ${serviceInterface.fileName?uncap_first};
}
}
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;
import org.apache.ibatis.annotations.Mapper;
/**
* @author ${author!}
* @description 针对表【${tableClass.tableName}<#if tableClass.remark?has_content>(${tableClass.remark!})</#if>】的数据库操作Mapper
* @createDate ${.now?string('yyyy-MM-dd HH:mm:ss')}
* @Entity ${tableClass.fullClassName}
*/
@Mapper
public interface ${mapperInterface.fileName} extends BaseMapper<${tableClass.shortClassName}> {
}
@JoJoJotarou
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment