mybatis-plus 代码生成器自定义模板变量API

本文介绍了mybatis-plus代码生成器如何进行自定义模板变量,涵盖了表信息的获取以及如何定制Controller模板,帮助开发者提高代码生成的灵活性。
部署运行你感兴趣的模型镜像

mybatis-plus 代码生成器自定义模板变量API

一、表信息

============table===========
TableInfo(
    importPackages=[
        com.baomidou.mybatisplus.annotation.TableName, 
        java.time.LocalDateTime, 
        java.io.Serializable
    ], 
    convert=true, 
    name=sys_user, 
    comment=系统用户表, 
    entityName=SysUserEntity, 
    mapperName=SysUserDao, 
    xmlName=SysUserMapper, 
    serviceName=SysUserService, 
    serviceImplName=SysUserServiceImpl, 
    controllerName=SysUserController, 

    
	fields=[
		TableField(
			convert=false, 
			keyFlag=true, 
			keyIdentityFlag=false, 
			name=id, 
			type=varchar(32), 
			propertyName=id, 
			columnType=STRING, 
			comment=主键id, 
			fill=null, 
			customMap=null
		), 
		TableField(
			convert=false, 
			keyFlag=false, 
			keyIdentityFlag=false, 
			name=username, 
			type=varchar(64), 
			propertyName=username, 
			columnType=STRING, 
			comment=用户名, 
			fill=null, 
			customMap=null
         )], 
    commonFields=[], 
    fieldNames=id, 
     	username, 
     	password,
        phone, 
        address, 
        in_date, 
        status, 
        remark, 
        card_id, 
        salt, 
        real_name
)

二、自定义Controller模板

/*
* 项目名称:${cfg.PROJECT_NAME}
* 类名称:${table.controllerName}.java
* 包名称:${package.Controller}
*
* 修改履历:
*      日期           修正者      主要内容
*      ${date}    ${author}      初版完成
*
* Copyright (c) 2017-2019 咨同科技
*/
package ${package.Controller};

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import ${package.Entity}.${table.entityName};
import ${package.Service}.${table.serviceName};
<#if restControllerStyle>
    import org.springframework.web.bind.annotation.RestController;
<#else>
    import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
    import ${superControllerClassPackage};
</#if>

import java.util.List;

/**
* <p>
* ${table.comment!} 前端控制器
* </p>
*
* @author ${author}
* @since ${date}
*/
<#if restControllerStyle>
    @RestController
<#else>
    @Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/${table.name?keep_after("_")?replace("_", "/")}")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
public class ${table.controllerName} {
    </#if>
</#if>

    @Autowired
    private ${table.serviceName} ${table.serviceName?uncap_first};

    /**
    * 增加${table.comment}
    *
    * @param ${table.entityName?uncap_first}
    * @return
    */
    @RequestMapping("/save")
    @RequiresPermissions("${table.name?keep_after("_")?replace("_", ":")}:save")
    public R save(@RequestBody ${table.entityName} ${table.entityName?uncap_first}) {
            ${table.serviceName?uncap_first}.save(${table.entityName?uncap_first});
        return R.ok();
    }

    /**
    * 删除${table.comment}
    *
    * @param id
    * @return
    */
    @RequestMapping("delete")
    @RequiresPermissions("${table.name?keep_after("_")?replace("_", ":")}:delete")
    public R delete(String id) {
            ${table.serviceName?uncap_first}.removeById(id);
        return R.ok();
    }

    /**
    * 修改${table.comment}
    *
    * @param ${table.entityName?uncap_first}
    * @return
    */
    @RequestMapping("update")
    @RequiresPermissions("${table.name?keep_after("_")?replace("_", ":")}:update")
    public R update(@RequestBody ${table.entityName} ${table.entityName?uncap_first}) {
            ${table.serviceName?uncap_first}.updateById(${table.entityName?uncap_first});
        return R.ok();
    }

    /**
    * 查看${table.comment}
    *
    * @return
    */
    @RequestMapping("list")
    @RequiresPermissions("${table.name?keep_after("_")?replace("_", ":")}:list")
    public R list() {
            List<${table.entityName}> sysDictEntityList = ${table.serviceName?uncap_first}.list();
        return R.ok(sysDictEntityList);
    }

}

您可能感兴趣的与本文相关的镜像

Seed-Coder-8B-Base

Seed-Coder-8B-Base

文本生成
Seed-Coder

Seed-Coder是一个功能强大、透明、参数高效的 8B 级开源代码模型系列,包括基础变体、指导变体和推理变体,由字节团队开源

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值