EasyCode 模板 .vm文件

用到swagger、mybatis plus,xml的sql自己修改

controller.java.vm

##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Controller"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/controller"))
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end
 
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller;
 
import $!{tableInfo.savePackageName}.pojo.$!{tableInfo.name};
import com.jxn.other.result.Result;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.alibaba.fastjson.JSONObject;
import java.util.Objects;

import org.springframework.beans.factory.annotation.Autowired;
 
/**
 * @Author $!author
 * @Desc $!{tableInfo.comment}($!{tableInfo.name})表控制层
 * @Date $!time.currTime()
 */
@Api(tags = "$!{tableInfo.comment}")
@Slf4j
@RestController
@RequestMapping("/$!tool.firstLowerCase($tableInfo.name)")
public class $!{tableName} {
    @Autowired
    private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;
 
    @ApiOperation("$!{tableInfo.comment}-搜索、分页查询")
    @DynamicParameters(name = "data", properties ={
            @DynamicParameter(name = "pageNo", value = "页码", example = "1", required = true),
            @DynamicParameter(name = "pageSize", value = "条数", example = "10", required = true),
    })
    @PostMapping("/search$!{tableInfo.name}")
    public Result search$!{tableInfo.name}(@RequestBody JSONObject data) {
        try {
            return $!{tool.firstLowerCase($tableInfo.name)}Service.search$!{tableInfo.name}(data);
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail("操作失败");
        }
    }

    @ApiOperation("$!{tableInfo.comment}-根据ID查详情")
    @DynamicParameters(name = "data", properties ={
            @DynamicParameter(name = "$!{tableInfo.name}Id", value = "id", example = "1", required = true),
    })
    @PostMapping("/$!{tableInfo.name}Detail")
    public Result $!{tableInfo.name}Detail(Integer $!{tool.firstLowerCase($tableInfo.name)}Id) {
        try {
            return $!{tool.firstLowerCase($tableInfo.name)}Service.$!{tool.firstLowerCase($tableInfo.name)}Detail($!{tool.firstLowerCase($tableInfo.name)}Id);
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail("操作失败");
        }
    }

    @ApiOperation("$!{tableInfo.comment}-新增数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "phone", value = "手机号", defaultValue = "10", required = true),
    })
    @PostMapping("/insert$!{tableInfo.name}")
    public Result insert$!{tableInfo.name}(@RequestBody $!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
        try {
            return $!{tool.firstLowerCase($tableInfo.name)}Service.insert$!{tableInfo.name}($!{tool.firstLowerCase($tableInfo.name)});
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail("操作失败");
        }
    }

    @ApiOperation("$!{tableInfo.comment}-编辑数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "phone", value = "手机号", defaultValue = "10", required = true),
    })
    @PostMapping("/update$!{tableInfo.name}")
    public Result update$!{tableInfo.name}(@RequestBody $!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
        try {
            if(Objects.isNull($!{tool.firstLowerCase($tableInfo.name)}.getId())){
                return Result.fail("id不能为空");
            }
            return $!{tool.firstLowerCase($tableInfo.name)}Service.update$!{tableInfo.name}($!{tool.firstLowerCase($tableInfo.name)});
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail("操作失败");
        }
    }

    @ApiOperation("$!{tableInfo.comment}-删除数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "$!{tableName}Id", value = "id", defaultValue = "1", required = true),
    })
    @GetMapping("/delete$!{tableInfo.name}")
    public Result delete$!{tableInfo.name}(Integer $!{tableInfo.comment}Id) {
        try {
        return $!{tool.firstLowerCase($tableInfo.name)}Service.delete$!{tableInfo.name}($!{tableInfo.comment}Id);
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail("操作失败");
        }
    }
 
}

service.java.vm

##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Service"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/service"))

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end

#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service;
import $!{tableInfo.savePackageName}.pojo.$!{tableInfo.name};
import com.alibaba.fastjson.JSONObject;
import com.jxn.other.result.Result;

/**
 * $!{tableInfo.comment}($!{tableInfo.name})表服务接口
 *
 * @author $!author
 * @since $!time.currTime()
 */
public interface $!{tableName} {

    /**
     * 搜索、分页查询
     *
     * @param data 筛选条件
     * @param 
     * @return 查询结果
     */
    Result search$!{tableInfo.name}(JSONObject data);

    /**
     * 通过ID查询单条数据详情
     *
     * @param $!pk.name 主键
     * @return 实例对象
     */
    Result $!tool.firstLowerCase($!{tableInfo.name})Detail ($!pk.shortType $!pk.name);
    
    /**
     * 新增数据
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
     * @return 实例对象
     */
    Result insert$!{tableInfo.name}($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));

    /**
     * 修改数据
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
     * @return 实例对象
     */
    Result update$!{tableInfo.name}($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));

    /**
     * 通过主键删除数据
     *
     * @param $!pk.name 主键
     * @return 是否成功
     */
    Result delete$!{tableInfo.name} ($!pk.shortType $!pk.name);

}

serviceImpl.java.vm

##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "ServiceImpl"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/service/impl"))

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end

#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service.impl;

import $!{tableInfo.savePackageName}.pojo.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.stereotype.Service;
import com.jxn.other.result.Result;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * $!{tableInfo.comment}($!{tableInfo.name})表服务实现类
 *"$!tool.firstLowerCase($!{tableInfo.name})Service"
 * @author $!author
 * @since $!time.currTime()
 */
@Service()
public class $!{tableName} implements $!{tableInfo.name}Service {
    @Autowired
    private $!{tableInfo.name}Mapper $!tool.firstLowerCase($!{tableInfo.name})Mapper;

    /**
     * 分页查询
     *
     * @param data 筛选条件
     * @return 查询结果
     */
    @Override
    public Result search$!{tableInfo.name}( JSONObject data ) {
        Integer pageNo=data.getInteger("pageNo");
        Integer pageSize=data.getInteger("pageSize");
        PageHelper.startPage(pageNo, pageSize);
        List<$!{tableInfo.name}> list = $!{tool.firstLowerCase($tableInfo.name)}Mapper.search$!{tableInfo.name}();
        PageInfo<$!{tableInfo.name}> info = new PageInfo<>(list);
        return Result.ok(info);
        }

    /**
     * 通过ID查询单条数据详情
     *
     * @param $!pk.name 主键
     * @return 实例对象
     */
    @Override
    public Result $!{tool.firstLowerCase($tableInfo.name)}Detail ($!pk.shortType $!pk.name) {
        $!{tableInfo.name} $!{tool.firstLowerCase($!{tableInfo.name})}=$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.$!{tool.firstLowerCase($tableInfo.name)}Detail ($!pk.name);
        return Result.ok();
    }
    
    /**
     * 新增数据
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
     * @return 实例对象
     */
    @Override
    public Result insert$!{tableInfo.name}($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
        $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.insert$!{tableInfo.name} ($!tool.firstLowerCase($!{tableInfo.name}));
        return Result.ok();
    }

    /**
     * 修改数据
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
     * @return 实例对象
     */
    @Override
    public Result update$!{tableInfo.name}($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
        $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.update$!{tableInfo.name}($!tool.firstLowerCase($!{tableInfo.name}));
        return Result.ok();
    }

    /**
     * 通过主键删除数据
     *
     * @param $!pk.name 主键
     * @return 是否成功
     */
    @Override
    public Result delete$!{tableInfo.name}($!pk.shortType $!pk.name) {
         $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.delete$!{tableInfo.name}($!pk.name);
         return Result.ok();
    }
}

mapper.java.vm

##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Mapper"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/mapper"))

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
    #set($pk = $tableInfo.pkColumn.get(0))
#end

#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}mapper;

import $!{tableInfo.savePackageName}.pojo.$!{tableInfo.name};
import org.apache.ibatis.annotations.Mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;

/**
 * $!{tableInfo.comment}($!{tableInfo.name})表数据库访问层
 *
 * @author $!author
 * @since $!time.currTime()
 */
@Mapper
public interface $!{tableName} extends BaseMapper<$!{tableInfo.name}> {

    /**
     * 搜索list
     *
     * @param $!pk.name 主键
     * @return 实例对象
     */
    List<$!{tableInfo.name}> search$!tool.firstLowerCase($!{tableInfo.name}) ();
    
    /**
     * 通过ID查询单条数据
     *
     * @param $!pk.name 主键
     * @return 实例对象
     */
    $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})Detail ($!pk.shortType $!pk.name);

    /**
     * 新增数据
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
     * @return 影响行数
     */
    int insert$!{tableInfo.name}(@Param("$!tool.firstLowerCase($!{tableInfo.name})") $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));

    /**
     * 修改数据
     *
     * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
     * @return 影响行数
     */
    int update$!{tableInfo.name}(@Param("$!tool.firstLowerCase($!{tableInfo.name})") $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));

    /**
     * 通过主键删除数据
     *
     * @param $!pk.name 主键
     * @return 影响行数
     */
    int delete$!{tableInfo.name}($!pk.shortType $!pk.name);

}

mapper.xml.vm 

##引入mybatis支持
$!{mybatisSupport.vm}

##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "Mapper.xml"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/mapper"))

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end





    
#foreach($column in $tableInfo.fullColumn)
        
#end
    

    
    

    
    

    
    

    
    
        insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)
        values (#foreach($column in $tableInfo.otherColumn)#{$!{column.name}}#if($velocityHasNext), #end#end)
    

    
        insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)
        values
        
        (#foreach($column in $tableInfo.otherColumn)#{pojo.$!{column.name}}#if($velocityHasNext), #end#end)
        
    

    
        insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)
        values
        
            (#foreach($column in $tableInfo.otherColumn)#{pojo.$!{column.name}}#if($velocityHasNext), #end#end)
        
        on duplicate key update
        #foreach($column in $tableInfo.otherColumn)$!column.obj.name = values($!column.obj.name)#if($velocityHasNext),
        #end#end

    

    
    
        update $!{tableInfo.obj.name}
        
#foreach($column in $tableInfo.otherColumn)
            
                $!column.obj.name = #{$!column.name},
            
#end
        
        where $!pk.obj.name = #{$!pk.name}
    

    
    
        delete from $!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name}
    


pojo.java.vm

##引入宏定义
$!{define.vm}
##使用宏定义设置回调(保存位置与文件后缀)
#save("/pojo", ".java")
##使用宏定义设置包后缀
#setPackageSuffix("pojo")
##使用全局变量实现默认包导入
$!{autoImport.vm}
import java.io.Serializable;
##使用宏定义实现类注释信息
#tableComment("实体类")
@TableName("$tableInfo.name")
@ApiModel(value = "$!{tableInfo.comment}")
public class $!{tableInfo.name} implements Serializable {
    #foreach($column in $tableInfo.pkColumn )
        #if(${column.comment})
        @TableId(value = "$tableInfo.pkColumn", type = IdType.AUTO)
        #break
        #end
    #end
    #foreach($column in $tableInfo.fullColumn)
        #if(${column.comment})
        /**
         * ${column.comment}
         */#end
        @ApiModelProperty(value = "$!column.name")
        private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
    #end

    #foreach($column in $tableInfo.fullColumn)
        ##使用宏定义实现get,set方法
        #getSetMethod($column)
    #end
}

你可能感兴趣的:(java,spring,开发语言,ide)