Commit 7afec11c by yubaogu

tett

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