pojo
##引入宏定义
$!{define.vm}
##使用宏定义设置回调(保存位置与文件后缀)
#save("/pojo", ".java")
##使用宏定义设置包后缀
#setPackageSuffix("pojo")
##使用全局变量实现默认包导入
$!{autoImport.vm}
import java.io.Serializable;
##使用宏定义实现类注释信息
#tableComment("实体类") $!entityName
@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
}
controller
##导入宏定义
$!{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))
import $!{tableInfo.savePackageName}.pojo.$!tableInfo.name;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
##表注释(宏定义)
#tableComment("表控制层")
@Slf4j
@Api(tags = "$!tableInfo.name 控制层")
@RestController("$!tool.firstLowerCase($!tableInfo.name)")
public class $!{tableName} {
/**
* 服务对象
*/
@Resource
private $!{tableInfo.name}Service $!{serviceName};
/**
* $!entityName 分页查询所有数据 $!tableInfo.name $!entityName
*
* @param data 分页对象
* @return 所有数据
*/
@ApiOperation(value = "分页查询所有数据", response = Result.class)
@DynamicParameters(name = "data", properties = {
@DynamicParameter(name = "pageNo", value = "页码", example = "1", required = true),
@DynamicParameter(name = "pageSize", value = "条数", example = "10", required = true),
@DynamicParameter(name = "replyType", value = "回复的对象1 2", example = "1", required = true),
@DynamicParameter(name = "type", value = "xx", example = "1", required = true),
@DynamicParameter(name = "parentId", value = "父 id", example = "1", required = true),
})
@PostMapping(value = "/selectAll")
public Result selectAll(@RequestBody JSONObject data) {
try {
PageInfo info = $!{serviceName}.selectAll(data);
return Result.ok(info);
} catch (Exception e) {
e.printStackTrace();
log.info(e.toString());
return Result.fail();
}
}
/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@ApiOperation(value = "主键查询单条数据", response = Result.class)
@DynamicParameters(name = "data", properties = {
@DynamicParameter(name = "id", value = "id", example = "1", required = true),
})
@GetMapping("{id}")
public Result selectOne(@PathVariable Serializable id) {
try {
return Result.ok($!{serviceName}.getById(id));
} catch (Exception e) {
e.printStackTrace();
log.info(e.toString());
return Result.fail();
}
}
/**
* 新增数据
*
* @param $!entityName 实体对象
* @return 新增结果
*/@ApiOperation(value = "新增数据", response = Result.class)
@DynamicParameters(name = "data", properties = {
//@DynamicParameter(name = "pageNo", value = "页码", example = "1", required = true),
//@DynamicParameter(name = "pageSize", value = "条数", example = "10", required = true),
//@DynamicParameter(name = "replyType", value = "回复的对象1 2", example = "1", required = true),
//@DynamicParameter(name = "type", value = "1表白墙 2交友 3工作 4黑企", example = "1", required = true),
//@DynamicParameter(name = "parentId", value = "父 id", example = "1", required = true),
})
@PostMapping
public Result insert(@RequestBody $!tableInfo.name $!entityName) {
try {
return Result.ok($!{serviceName}.save($!entityName));
} catch (Exception e) {
e.printStackTrace();
log.info(e.toString());
return Result.fail();
}
}
/**
* 修改数据
*
* @param $!entityName 实体对象
* @return 修改结果
*/
@ApiOperation(value = "修改数据", response = Result.class)
@DynamicParameters(name = "data", properties = {
//@DynamicParameter(name = "pageNo", value = "页码", example = "1", required = true),
//@DynamicParameter(name = "pageSize", value = "条数", example = "10", required = true),
//@DynamicParameter(name = "replyType", value = "回复的1 2", example = "1", required = true),
//@DynamicParameter(name = "type", value = "", example = "1", required = true),
//@DynamicParameter(name = "parentId", value = "父 id", example = "1", required = true),
})
@PutMapping
public Result update(@RequestBody $!tableInfo.name $!entityName) {
try {
return Result.ok($!{serviceName}.updateById($!entityName));
} catch (Exception e) {
e.printStackTrace();
log.info(e.toString());
return Result.fail();
}
}
/**
* 删除数据
*
* @param idList 主键结合
* @return 删除结果
*/
@ApiOperation(value = "删除数据", response = Result.class)
@DynamicParameters(name = "data", properties = {
@DynamicParameter(name = "idList", value = "id", example = "1,2", required = true),
})
@DeleteMapping
public Result delete(@RequestParam("idList") List idList) {
try {
return Result.ok($!{serviceName}.removeByIds(idList));
} catch (Exception e) {
e.printStackTrace();
log.info(e.toString());
return Result.fail();
}
}
}
mapper
##导入宏定义
$!{define.vm}
##设置表后缀(宏定义)
#setTableSuffix("Mapper")
##保存文件(宏定义)
#save("/mapper", "Mapper.java")
##包路径(宏定义)
#setPackageSuffix("mapper")
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import $!{tableInfo.savePackageName}.pojo.$!tableInfo.name;
##表注释(宏定义)
#tableComment("表数据库访问层")
@Mapper
public interface $!{tableName} extends BaseMapper<$!tableInfo.name> {
}
service
##导入宏定义
$!{define.vm}
##设置表后缀(宏定义)
#setTableSuffix("Service")
##保存文件(宏定义)
#save("/service", "Service.java")
##包路径(宏定义)
#setPackageSuffix("service")
import com.baomidou.mybatisplus.extension.service.IService;
import $!{tableInfo.savePackageName}.pojo.$!tableInfo.name;
##表注释(宏定义)
#tableComment("表服务接口")
public interface $!{tableName} extends IService<$!tableInfo.name> {
public PageInfo selectAll(JSONObject data);
}
serviceImpl
##导入宏定义
$!{define.vm}
##设置表后缀(宏定义)
#setTableSuffix("ServiceImpl")
##保存文件(宏定义)
#save("/service/impl", "ServiceImpl.java")
##包路径(宏定义)
#setPackageSuffix("service.impl")
##定义服务名
#set($mapperName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Mapper"))
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper;
import $!{tableInfo.savePackageName}.pojo.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.stereotype.Service;
##表注释(宏定义)
#tableComment("表服务实现类")
@Service("$!tool.firstLowerCase($tableInfo.name)Service")
public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Mapper, $!{tableInfo.name}> implements $!{tableInfo.name}Service {
@Autowired
$!{tableInfo.name}Mapper $!{mapperName};
/**
* 分页查询所有数据
* @param data
* @return
*/
@Override
public PageInfo selectAll(JSONObject data) {
QueryWrapper<$!{tableInfo.name}> wrapper = new QueryWrapper<>();
wrapper.eq("type", data.getString("type"));
wrapper.eq("parent_id", data.getInteger("parentId"));
//wrapper.eq("createTime", data.get("createTime") + " 00:00:00");
wrapper.orderByDesc("create_time");
PageHelper.startPage(data.getInteger("pageNo"), data.getInteger("pageSize"));
List<$!{tableInfo.name}> list = $!{mapperName}.selectList(wrapper);
PageInfo info = new PageInfo(list);
return info;
}
}
修改作者
路径:Settings --> Other Settings---> EasyCode