easycode 自定义模板

项目使用:

controller.java.vm

##导入宏定义
$!{define.vm}

##设置表后缀(宏定义)
#setTableSuffix("Controller")

##保存文件(宏定义)
#save("/controller", "Controller.java")

##包路径(宏定义)
#setPackageSuffix("controller")

##定义服务名
#set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service"))

##定义实体对象名
#set($entityName = $!tool.firstLowerCase($!tableInfo.name))
#set($PkType = $!{tool.getClsNameByFullName($!tableInfo.pkColumn[0].type)})

import $!{tableInfo.savePackageName}.utils.BaseResult;
import $!{tableInfo.savePackageName}.entity.$!tableInfo.name;
import $!{tableInfo.savePackageName}.vo.req.$!{tableInfo.name}Req;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

##表注释(宏定义)
#tableComment("表控制层")
@RestController
@Api(tags = "$!{tableInfo.comment}($!{tableInfo.name})")
@RequestMapping("$!tool.firstLowerCase($!tableInfo.name)")
public class $!{tableName}{
    /**
     * 服务对象
     */
    @Resource
    private $!{tableInfo.name}Service $!{serviceName};

    /**
     * 分页查询所有数据
     *
     * @param $!{entityName}Req 查询实体
     * @return 所有数据
     */
    @PostMapping("/selectAll")
    @ApiOperation(value = "分页查全部")
    public BaseResult selectAll(@RequestHeader Long userId, @RequestBody @ApiParam $!{tableInfo.name}Req $!{entityName}Req) {
        return BaseResult.success(this.$!{serviceName}.list$!{tableInfo.name}(userId, $!{entityName}Req));

    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @PostMapping("{id}")
    @ApiOperation(value = "根据id查")
    public BaseResult selectOne(@RequestHeader Long userId,  @ApiParam(required = true)  $!{PkType} id) {
        return BaseResult.success(this.$!{serviceName}.getById(id));
    }

    /**
     * 新增数据
     *
     * @param $!entityName 实体对象
     * @return 新增结果
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加")
    public BaseResult insert(@RequestHeader Long userId, @RequestBody @ApiParam $!tableInfo.name $!entityName) {
        return BaseResult.success(this.$!{serviceName}.save($!entityName));
    }

    /**
     * 修改数据
     *
     * @param $!entityName 实体对象
     * @return 修改结果
     */
    @PostMapping("/update")
    @ApiOperation(value = "更新")
    public BaseResult update(@RequestHeader Long userId, @RequestBody @ApiParam $!tableInfo.name $!entityName) {
        return BaseResult.success(this.$!{serviceName}.updateById($!entityName));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @PostMapping("/del")
    @ApiOperation(value = "删除")
    public BaseResult delete(@RequestHeader Long userId, @RequestBody @ApiParam List<$!{PkType}> idList) {
        return BaseResult.success(this.$!{serviceName}.removeByIds(idList));
    }
}

entity.java.vm

##导入宏定义
$!{define.vm}

##保存文件(宏定义)
#save("/entity", ".java")

##包路径(宏定义)
#setPackageSuffix("entity")

##自动导入包(全局变量)
$!autoImport
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.time.LocalDateTime;

import java.io.Serializable;

##表注释(宏定义)
#tableComment("表实体类")
@Data
@ApiModel("$tableInfo.comment")
@TableName(value = "$!{tableInfo.obj.name}")
public class $!{tableInfo.name} extends Model<$!{tableInfo.name}> implements Serializable {
    private static final long serialVersionUID = $!tool.serial();
#foreach($column in $tableInfo.fullColumn)
    ##if(${column.comment})/**
    ##* ${column.comment}
    ##*/#end
    
#if($column.obj.name == "id")
    @TableId(type = IdType.AUTO)
#end
    @ApiModelProperty("$column.comment")
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
}

mapper.xml.vm

##引入mybatis支持
$!{mybatisSupport.vm}
##定义实体对象名
#set($entityName = $!tool.firstLowerCase($!tableInfo.name))

##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "Mapping.xml"))
$!callback.setSa
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值