mybatis-plusコードジェネレータカスタムテンプレート変数API

9018 ワード

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
)

二、コントローラテンプレートのカスタマイズ
/*
*     :${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};

    import org.springframework.web.bind.annotation.RestController;

    import org.springframework.stereotype.Controller;
#if>

    import ${superControllerClassPackage};
#if>

import java.util.List;

/**
* 

* ${table.comment!} *

* * @author ${author} * @since ${date} */ @RestController @Controller #if> @RequestMapping("/${package.ModuleName}#if>/${table.name?keep_after("_")?replace("_", "/")}") class ${table.controllerName} : ${superControllerClass}()#if> public class ${table.controllerName} extends ${superControllerClass} { 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 sysDictEntityList = ${table.serviceName?uncap_first}.list(); return R.ok(sysDictEntityList); } }