本文主要是介绍mybatisx 插件模板,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
mybatis-plus3:
.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>
domain.ftl
package ${domain.packageName};import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import javax.validation.constraints.NotNull;import java.io.Serializable;
<#list tableClass.importList as fieldType>${"\n"}import ${fieldType};</#list>
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiModel;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.IdType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;/*** ${tableClass.remark!}** @author * @date ${.now?string('yyyy-MM-dd')}*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "${tableClass.remark!}")
public class ${tableClass.shortClassName} implements Serializable {<#list tableClass.allFields as field>/*** ${field.remark!}*/<#if !field.nullable || field.jdbcType=="VARCHAR">${"\n "}</#if><#if !field.nullable><#if field.jdbcType=="VARCHAR">@NotBlank(message="[${field.remark!}]不能为空")<#else>@NotNull(message="[${field.remark!}]不能为空")</#if></#if><#if field.jdbcType=="VARCHAR"><#if !field.nullable>${"\n "}</#if>@Size(max= ${field.columnLength?c},message="编码长度不能超过${field.columnLength?c}")</#if>@ApiModelProperty("${field.remark!}")<#if field.jdbcType=="VARCHAR">${"\n "}@Length(max= ${field.columnLength},message="编码长度不能超过${field.columnLength}")</#if><#if field.fieldName=="id">@TableId(type = IdType.AUTO)${"\n "}</#if>private ${field.shortTypeName} ${field.fieldName};</#list>}
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;/**
* <#if tableClass.remark?has_content>${tableClass.remark!}</#if>
*
* @author
* @date: ${.now?string('yyyy-MM-dd')}
*/
public interface ${mapperInterface.fileName} extends BaseMapper<${tableClass.shortClassName}> {}
mapperXml.ftl
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapperPUBLIC "-//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>
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
* @date ${.now?string('yyyy-MM-dd')}
*/
@Service
public class ${baseInfo.fileName} extends ServiceImpl<${mapperInterface.fileName}, ${tableClass.shortClassName}>implements ${serviceInterface.fileName}{}
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;/**
* <p>
* <#if tableClass.remark?has_content>${tableClass.remark!}</#if>
* </p>
*
* @author
* @date ${.now?string('yyyy-MM-dd')}
*/
public interface ${baseInfo.fileName} extends IService<${tableClass.shortClassName}> {}
这篇关于mybatisx 插件模板的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!