Commit 7afec11c by yubaogu

tett

parent 306bb19e
/**
* @filename:${entityName}Controller ${createTime}
* @project ${project} ${version}
* Copyright(c) 2020 ${author} Co. Ltd.
* All right reserved.
*/
package ${abstractControllerUrl};
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gitee.flying.cattle.mdg.aid.JsonResult;
import com.gitee.flying.cattle.mdg.aid.PageParam;
<#if isSwagger=="true" >
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
</#if>
/**
* @Description:TODO(${entityComment}API接口层)
*
* @version: ${version}
* @author: ${author}
* @time ${createTime}
*/
public class AbstractController<S extends IService<T>,T>{
@Autowired
protected S baseService;
protected JsonResult<T> result = new JsonResult<T>();
/**
* @explain 查询对象 <swagger GET请求>
* @param 对象参数:id
* @return JsonResult
* @author ${author}
* @time ${createTime}
*/
@GetMapping("/getById/{id}")
<#if isSwagger=="true" >
@ApiOperation(value = "获取对象", notes = "作者:${author}")
@ApiImplicitParam(paramType="path", name = "id", value = "对象id", required = true, dataType = "Long")
</#if>
public JsonResult<T> getById(@PathVariable("id")Long id){
T obj=baseService.getById(id);
if (null!=obj ) {
result.success(obj);
}else {
result.error("查询对象不存在!");
}
return result;
}
/**
* @explain 删除对象
* @param 对象参数:id
* @return JsonResult
* @author ${author}
* @time ${createTime}
*/
@PostMapping("/deleteById")
<#if isSwagger=="true" >
@ApiOperation(value = "删除", notes = "作者:${author}")
@ApiImplicitParam(paramType="query", name = "id", value = "对象id", required = true, dataType = "Long")
</#if>
public JsonResult<T> deleteById(Long id){
JsonResult<T> result=new JsonResult<T>();
T obj=baseService.getById(id);
if (null!=obj) {
boolean rsg = baseService.removeById(id);
if (rsg) {
result.success("删除成功");
}else {
result.error("删除失败!");
}
}else {
result.error("删除的对象不存在!");
}
return result;
}
/**
* @explain 添加
* @param 对象参数:T
* @return Boolean
* @author ${author}
* @time ${createTime}
*/
@PostMapping("/insert")
<#if isSwagger=="true" >
@ApiOperation(value = "添加", notes = "作者:${author}")
</#if>
public JsonResult<T> insert(T entity){
JsonResult<T> result=new JsonResult<T>();
if (null!=entity) {
boolean rsg = baseService.save(entity);
if (rsg) {
result.success("添加成功");
}else {
result.error("添加失败!");
}
}else {
result.error("请传入正确参数!");
}
return result;
}
/**
* @explain 修改
* @param 对象参数:T
* @return Boolean
* @author ${author}
* @time ${createTime}
*/
@PostMapping("/update")
<#if isSwagger=="true" >
@ApiOperation(value = "修改", notes = "作者:${author}")
</#if>
public JsonResult<T> update(T entity){
JsonResult<T> result=new JsonResult<T>();
if (null!=entity) {
boolean rsg = baseService.updateById(entity);
if (rsg) {
result.success("修改成功");
}else {
result.error("修改失败!");
}
}else {
result.error("请传入正确参数!");
}
return result;
}
/**
* @explain 分页条件查询用户
* @param 对象参数:AppPage<${entityName}>
* @return PageInfo<${entityName}>
* @author ${author}
* @time ${createTime}
*/
@GetMapping("/getPages")
<#if isSwagger=="true" >
@ApiOperation(value = "分页查询", notes = "分页查询返回[IPage<T>],作者:${author}")
</#if>
public JsonResult<IPage<T>> getPages(PageParam<T> param){
JsonResult<IPage<T>> returnPage=new JsonResult<IPage<T>>();
Page<T> page=new Page<T>(param.getPageNum(),param.getPageSize());
QueryWrapper<T> queryWrapper =new QueryWrapper<T>();
queryWrapper.setEntity(param.getParam());
//分页数据
IPage<T> pageData=baseService.page(page, queryWrapper);
returnPage.success(pageData);
return returnPage;
}
}
/**
* @filename:${entityName}Controller ${createTime}
* @project ${project} ${version}
* Copyright(c) 2020 ${author} Co. Ltd.
* All right reserved.
*/
package ${abstractControllerUrl};
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import com.gitee.flying.cattle.mdg.aid.JsonResult;
import com.gitee.flying.cattle.mdg.aid.PageParam;
<#if isSwagger=="true" >
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
</#if>
/**
* @Description:TODO(${entityComment}API接口层)
*
* @version: ${version}
* @author: ${author}
* @time ${createTime}
*/
public class AbstractController<S extends IService<T>,T>{
@Autowired
protected S baseService;
protected JsonResult<T> result = new JsonResult<T>();
/**
* @explain 查询对象 <swagger GET请求>
* @param 对象参数:id
* @return JsonResult
* @author ${author}
* @time ${createTime}
*/
@GetMapping("/getById/{id}")
<#if isSwagger=="true" >
@ApiOperation(value = "获取对象", notes = "作者:${author}")
@ApiImplicitParam(paramType="path", name = "id", value = "对象id", required = true, dataType = "Long")
</#if>
public JsonResult<T> getById(@PathVariable("id")Long id){
T obj=baseService.getById(id);
if (null!=obj ) {
result.success(obj);
}else {
result.error("查询对象不存在!");
}
return result;
}
/**
* @explain 删除对象
* @param 对象参数:id
* @return JsonResult
* @author ${author}
* @time ${createTime}
*/
@PostMapping("/deleteById")
<#if isSwagger=="true" >
@ApiOperation(value = "删除", notes = "作者:${author}")
@ApiImplicitParam(paramType="query", name = "id", value = "对象id", required = true, dataType = "Long")
</#if>
public JsonResult<T> deleteById(Long id){
JsonResult<T> result=new JsonResult<T>();
T obj=baseService.getById(id);
if (null!=obj) {
boolean rsg = baseService.removeById(id);
if (rsg) {
result.success("删除成功");
}else {
result.error("删除失败!");
}
}else {
result.error("删除的对象不存在!");
}
return result;
}
/**
* @explain 添加
* @param 对象参数:T
* @return Boolean
* @author ${author}
* @time ${createTime}
*/
@PostMapping("/insert")
<#if isSwagger=="true" >
@ApiOperation(value = "添加", notes = "作者:${author}")
</#if>
public JsonResult<T> insert(T entity){
JsonResult<T> result=new JsonResult<T>();
if (null!=entity) {
boolean rsg = baseService.save(entity);
if (rsg) {
result.success("添加成功");
}else {
result.error("添加失败!");
}
}else {
result.error("请传入正确参数!");
}
return result;
}
/**
* @explain 修改
* @param 对象参数:T
* @return Boolean
* @author ${author}
* @time ${createTime}
*/
@PostMapping("/update")
<#if isSwagger=="true" >
@ApiOperation(value = "修改", notes = "作者:${author}")
</#if>
public JsonResult<T> update(T entity){
JsonResult<T> result=new JsonResult<T>();
if (null!=entity) {
boolean rsg = baseService.updateById(entity);
if (rsg) {
result.success("修改成功");
}else {
result.error("修改失败!");
}
}else {
result.error("请传入正确参数!");
}
return result;
}
/**
* @explain 分页条件查询用户
* @param 对象参数:AppPage<${entityName}>
* @return PageInfo<${entityName}>
* @author ${author}
* @time ${createTime}
*/
@GetMapping("/getPages")
<#if isSwagger=="true" >
@ApiOperation(value = "分页查询", notes = "分页查询返回[IPage<T>],作者:${author}")
</#if>
public JsonResult<IPage<T>> getPages(PageParam<T> param){
JsonResult<IPage<T>> returnPage=new JsonResult<IPage<T>>();
Page<T> page=new Page<T>(param.getPageNum(),param.getPageSize());
QueryWrapper<T> queryWrapper =new QueryWrapper<T>();
queryWrapper.setEntity(param.getParam());
//分页数据
IPage<T> pageData=baseService.page(page, queryWrapper);
returnPage.success(pageData);
return returnPage;
}
}
/**
* @filename:${entityName}Dao ${createTime}
* @project ${project} ${version}
* Copyright(c) 2020 ${author} Co. Ltd.
* All right reserved.
*/
package ${daoUrl};
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import ${entityUrl}.${entityName};
/**
* @Description:TODO(${entityComment}数据访问层)
*
* @version: ${version}
* @author: ${author}
*
*/
@Mapper
public interface ${entityName}Dao extends BaseMapper<${entityName}> {
}
/**
* @filename:${entityName}Dao ${createTime}
* @project ${project} ${version}
* Copyright(c) 2020 ${author} Co. Ltd.
* All right reserved.
*/
package ${daoUrl};
import com.ydl.common.service.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import ${entityUrl}.${entityName};
/**
* @Description:TODO(${entityComment}数据访问层)
*
* @version: ${version}
* @author: ${author}
*
*/
@Mapper
public interface ${entityName}Dao extends BaseMapper<${entityName}> {
}
\ No newline at end of file
/**
* @filename:${entityName} ${createTime}
* @project ${project} ${version}
* Copyright(c) 2020 ${author} Co. Ltd.
* All right reserved.
*/
package ${entityUrl};
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
<#if isSwagger=="true" >
import io.swagger.annotations.ApiModelProperty;
</#if>
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
<#list pkgs as ps>
<#if ps??>
import ${ps};
</#if>
</#list>
/**
* @Description:TODO(${entityComment}实体类)
*
* @version: ${version}
* @author: ${author}
*
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class ${entityName} extends Model<${entityName}> {
private static final long serialVersionUID = ${agile}L;
<#list cis as ci>
<#if ci.javaType=="Date">
<#if ci.jdbcType=="date">
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
<#elseif ci.jdbcType=="time">
@DateTimeFormat(pattern = "HH:mm:ss")
@JsonFormat(pattern="HH:mm:ss",timezone = "GMT+8")
<#else>
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
</#if>
</#if>
<#if ci.property=="id">
@TableId(value = "id", type = IdType.AUTO)
</#if>
<#if isSwagger=="true" >
@ApiModelProperty(name = "${ci.property}" , value = "${ci.comment}")
</#if>
private ${ci.javaType} ${ci.property};
</#list>
@Override
protected Serializable pkVal() {
return this.id;
}
}
/**
* @filename:${entityName} ${createTime}
* @project ${project} ${version}
* Copyright(c) 2020 ${author} Co. Ltd.
* All right reserved.
*/
package ${entityUrl};
import com.fasterxml.jackson.annotation.JsonFormat;
<#if isSwagger=="true" >
import io.swagger.annotations.ApiModelProperty;
</#if>
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
<#list pkgs as ps>
<#if ps??>
import ${ps};
</#if>
</#list>
/**
* @Description:TODO(${entityComment}实体类)
*
* @version: ${version}
* @author: ${author}
*
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class ${entityName} extends Model<${entityName}> {
private static final long serialVersionUID = ${agile}L;
<#list cis as ci>
<#if ci.javaType=="Date">
<#if ci.jdbcType=="date">
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
<#elseif ci.jdbcType=="time">
@DateTimeFormat(pattern = "HH:mm:ss")
@JsonFormat(pattern="HH:mm:ss",timezone = "GMT+8")
<#else>
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
</#if>
</#if>
<#if ci.property=="id">
@TableId(value = "id", type = IdType.AUTO)
</#if>
<#if isSwagger=="true" >
@ApiModelProperty(name = "${ci.property}" , value = "${ci.comment}")
</#if>
private ${ci.javaType} ${ci.property};
</#list>
@Override
protected Serializable pkVal() {
return this.id;
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${daoUrl}.${entityName}Dao">
<resultMap id="BaseResultMap" type="${entityUrl}.${entityName}">
<#list cis as ci>
<id column="${ci.column}" property="${ci.property}" />
</#list>
</resultMap>
<sql id="Base_Column_List">
${agile}
</sql>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${daoUrl}.${entityName}Mapper">
<resultMap id="BaseResultMap" type="${entityUrl}.${entityName}">
<#list cis as ci>
<id column="${ci.column}" property="${ci.property}" />
</#list>
</resultMap>
<sql id="Base_Column_List">
${agile}
</sql>
</mapper>
\ No newline at end of file
/**
* @filename:${entityName}Service ${createTime}
* @project ${project} ${version}
* Copyright(c) 2020 ${author} Co. Ltd.
* All right reserved.
*/
package ${serviceUrl};
import ${entityUrl}.${entityName};
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @Description:TODO(${entityComment}服务层)
* @version: ${version}
* @author: ${author}
*
*/
public interface ${entityName}Service extends IService<${entityName}> {
/**
* @filename:${entityName}Service ${createTime}
* @project ${project} ${version}
* Copyright(c) 2020 ${author} Co. Ltd.
* All right reserved.
*/
package ${serviceUrl};
import com.ydl.common.service.IService;
import ${entityUrl}.${entityName};
/**
* @Description:TODO(${entityComment}服务层)
* @version: ${version}
* @author: ${author}
*
*/
public interface ${entityName}Service extends IService<${entityName}> {
}
\ No newline at end of file
/**
* @filename:${entityName}ServiceImpl ${createTime}
* @project ${project} ${version}
* Copyright(c) 2018 ${author} Co. Ltd.
* All right reserved.
*/
package ${serviceImplUrl};
import ${entityUrl}.${entityName};
import ${daoUrl}.${entityName}Dao;
import ${serviceUrl}.${entityName}Service;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
/**
* @Description:TODO(${entityComment}服务实现)
*
* @version: ${version}
* @author: ${author}
*
*/
@Service
public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Dao, ${entityName}> implements ${entityName}Service {
/**
* @filename:${entityName}ServiceImpl ${createTime}
* @project ${project} ${version}
* Copyright(c) 2018 ${author} Co. Ltd.
* All right reserved.
*/
package ${serviceImplUrl};
import ${entityUrl}.${entityName};
import ${daoUrl}.${entityName}Dao;
import ${serviceUrl}.${entityName}Service;
import org.springframework.stereotype.Service;
import com.ydl.common.service.impl.BaseService;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import com.github.pagehelper.PageHelper;
/**
* @Description:TODO(${entityComment}服务实现)
*
* @version: ${version}
* @author: ${author}
*
*/
@Service
public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Dao, ${entityName}> implements ${entityName}Service {
}
\ No newline at end of file
......@@ -46,7 +46,7 @@ public class MyGenerator {
public static final String XML_URL = "com.buybit.power.mapper.xml";
public static final String SERVICE_URL = "com.buybit.power.service";
public static final String SERVICE_IMPL_URL = "com.buybit.power.service.impl";
public static final String CONTROLLER_URL = "com.buybit.power.web";
public static final String CONTROLLER_URL = "com.buybit.power.api";
//是否是Swagger配置
public static final String IS_SWAGGER = "true";
......@@ -60,7 +60,7 @@ public class MyGenerator {
bi.setEntityComment(CLASSCOMMENT);
try {
bi = EntityInfoUtil.getInfo(bi);
String fileUrl = "D:\\ydlwork\\generator\\";// 生成文件存放位置
String fileUrl = "D:\\ydlwork\\generator\\demo\\src\\main\\java\\";// 生成文件存放位置
//开始生成文件
String aa1 = Generator.createEntity(fileUrl, bi).toString();
String aa2 = Generator.createDao(fileUrl, bi).toString();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment