栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

EasuCode模板

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

EasuCode模板

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 com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import com.liberty.androidtools.server.result.ServiceResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@Api(tags = "$!{tableInfo.comment}")
@RestController
@RequestMapping("$!tool.firstLowerCase($tableInfo.name)")
public class $!{tableName} {

    @Autowired
    $!{tableInfo.name}Service service;

    
    @ApiOperation(value = "新增记录", notes = "新增记录")
    @ApiOperationSupport(order = 1, author = "FXR")
    @PostMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ServiceResult<$!{tableInfo.name}> add(@RequestBody @ApiParam("json格式对象") $!{tableInfo.name} entity) {
        service.save(entity);
        return ServiceResult.success(entity);
    }
    
    
    @ApiOperation(value = "删除记录", notes = "删除记录")
    @ApiOperationSupport(order = 2, author = "FXR")
    @DeleteMapping(value = "/{ids}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ServiceResult delete(@PathVariable("ids") @ApiParam(value = "删除的id", required = true) String... ids) {
        return ServiceResult.success(service.removeByIds(Arrays.asList(ids)));
    }
    
    
    @ApiOperation(value = "修改记录", notes = "修改记录")
    @ApiOperationSupport(order = 3, author = "FXR")
    @PutMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ServiceResult update(@RequestBody @ApiParam(value = "json格式对象", required = true) $!{tableInfo.name} entity) {
        return ServiceResult.success(service.updateById(entity));
    }

    
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @ApiOperationSupport(order = 4, author = "FXR")
    @GetMapping(value = "page", produces = MediaType.APPLICATION_JSON_VALUE)
    public ServiceResult> page(@ApiParam("分页查询的分页数据模型") Page<$!{tableInfo.name}> pageQuery,@ApiParam("json格式对象")  $!{tableInfo.name} query) {
        return ServiceResult.success(service.page(pageQuery, Wrappers.lambdaQuery(query).orderByDesc($!{tableInfo.name}::getCreateTime)));
    }

    
    @ApiOperation(value = "查询列表", notes = "查询列表")
    @ApiOperationSupport(order = 5, author = "FXR")
    @GetMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE)
    public ServiceResult> list(@ApiParam("查询的搜索条件") $!{tableInfo.name} query) {
        return ServiceResult.success(service.list(Wrappers.lambdaQuery(query).orderByDesc($!{tableInfo.name}::getCreateTime)));
    }

    
    @ApiOperation(value = "查询详情", notes = "查询详情")
    @ApiOperationSupport(order = 6, author = "FXR")
    @GetMapping(value = "/info/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ServiceResult<$!{tableInfo.name}> info(@PathVariable("id") @ApiParam(value = "查询的ID", required = true) String id) {
        return ServiceResult.success(service.getById(id));
    }

    
    @ApiOperation(value = "根据id集合查询", notes = "根据id集合查询")
    @ApiOperationSupport(order = 7, author = "FXR")
    @GetMapping(value = "/listByIds/{ids}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ServiceResult> listByIds(@PathVariable("ids") @ApiParam(value = "查询的ID", required = true) String... ids) {
        return ServiceResult.success(service.listByIds(Arrays.asList(ids)));
    }

}

dao.java.vm

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

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

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

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


@Mapper
public interface $!{tableName} extends baseMapper<$!{tableInfo.name}> {
}

entity.java.vm

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

##使用宏定义设置回调(保存位置与文件后缀)
#save("/entity", ".java")

##使用宏定义设置包后缀
#setPackageSuffix("entity")

##使用全局变量实现默认包导入
$!{autoimport.vm}
import java.io.Serializable;
##使用全局变量实现默认包导入
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.liberty.androidtools.server.modules.base.AbstractEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
$!autoimport
import java.io.Serializable;

##使用宏定义实现类注释信息
#tableComment("实体类")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@TableName("$!tableInfo.obj.name")
public class $!{tableInfo.name} extends AbstractEntity implements Serializable {
    private static final long serialVersionUID = $!tool.serial();
#foreach($column in $tableInfo.fullColumn)
    #if(${column.obj.name} != "ID")
        #if(${column.obj.name} != "CREATE_BY")
            #if(${column.obj.name} != "CREATE_TIME")
                #if(${column.obj.name} != "UPDATE_BY")
                    #if(${column.obj.name} != "UPDATE_TIME")
                        #if(${column.obj.name} != "DEL_FLAG")
                            #if(${column.obj.name} != "REMARK")

                                #if(${column.comment})#end
    
    @ApiModelProperty(value = "${column.comment}")
    @TableField(value = "${column.obj.name}")
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
                        #end
                    #end
                #end
            #end
        #end
    #end
#end

}

mapper.xml.vm

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

##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "Dao.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
    

    
    
        select
          #allSqlColumn()

        from $!tableInfo.obj.name
        
#foreach($column in $tableInfo.fullColumn)
            
                and $!column.obj.name = #{$!column.name}
            
#end
        
        limit #{pageable.offset}, #{pageable.pageSize}