Skip to content

Commit

Permalink
优化代码生成器代码
Browse files Browse the repository at this point in the history
  • Loading branch information
zlt2000 committed Oct 4, 2019
1 parent e85a95e commit 2c6c24b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import ${package}.${moduleName}.model.${className};
import ${package}.${moduleName}.service.${className}Service;
import ${package}.${moduleName}.service.I${className}Service;
import com.central.common.model.PageResult;
import com.central.common.model.Result;

Expand All @@ -37,7 +37,7 @@ public class ${className}Controller {
@ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"),
@ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer")
})
@GetMapping("/${className}")
@GetMapping
public PageResult list(@RequestParam Map<String, Object> params) {
return ${classname}Service.findList(params);
}
Expand All @@ -46,27 +46,27 @@ public class ${className}Controller {
* 查询
*/
@ApiOperation(value = "查询")
@GetMapping("/${className}/{id}")
@GetMapping("/{${pk.attrname}}")
public Result findUserById(@PathVariable Long ${pk.attrname}) {
${className} model = ${classname}Service.getById(id);
${className} model = ${classname}Service.getById(${pk.attrname});
return Result.succeed(model, "查询成功");
}

/**
* 新增or更新
*/
@ApiOperation(value = "保存")
@PostMapping("/${className}")
@PostMapping
public Result save(@RequestBody ${className} ${classname}) {
${classname}Service.saveOrUpdateUser(${classname});
${classname}Service.saveOrUpdate(${classname});
return Result.succeed("保存成功");
}

/**
* 删除
*/
@ApiOperation(value = "删除")
@DeleteMapping("/${className}/{id}")
@DeleteMapping("/{id}")
public Result delete(@PathVariable Long ${pk.attrname}) {
${classname}Service.removeById(${pk.attrname});
return Result.succeed("删除成功");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ${package}.${moduleName}.dao;
package ${package}.${moduleName}.mapper;

import ${package}.${moduleName}.entity.${className};
import ${package}.${moduleName}.model.${className};
import com.central.db.mapper.SuperMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
Expand All @@ -14,7 +14,6 @@ import java.util.Map;
* @author ${author}
* @date ${datetime}
*/
@Mapper
public interface ${className}Mapper extends SuperMapper<${className}> {
/**
* 分页查询用户列表
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
<mapper namespace="${package}.${moduleName}.mapper.${className}Mapper">
<select id="findList" resultType="${package}.${moduleName}.model.${className}">
select * from ${tableName} t
order by t.id desc
</select>
</mapper>
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package ${package}.${moduleName}.model;

import com.baomidou.mybatisplus.annotations.TableName;
import ${package}.common.model.SuperEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.EqualsAndHashCode;
#if(${hasBigDecimal})
import java.math.BigDecimal;
#end
import java.io.Serializable;
import java.util.Date;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package ${package}.${moduleName}.service;

import ${package}.${moduleName}.entity.${className};
import ${package}.${moduleName}.model.${className};
import com.central.common.model.PageResult;
import com.central.common.model.Result;
import com.baomidou.mybatisplus.extension.service.IService;
import ${package}.common.service.ISuperService;

import java.util.Map;

Expand All @@ -13,7 +12,7 @@ import java.util.Map;
* @author ${author}
* @date ${datetime}
*/
public interface I${className}Service extends IService<${className}> {
public interface I${className}Service extends ISuperService<${className}> {
/**
* 列表
* @param params
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package ${package}.${moduleName}.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.central.common.model.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import ${package}.common.service.impl.SuperServiceImpl;

import java.util.List;
import java.util.Map;
import org.apache.commons.collections4.MapUtils;
import lombok.extern.slf4j.Slf4j;

import ${package}.${moduleName}.entity.${className};
import ${package}.${moduleName}.dao.${className}Dao;
import ${package}.${moduleName}.service.${className}Service;
import ${package}.${moduleName}.model.${className};
import ${package}.${moduleName}.mapper.${className}Mapper;
import ${package}.${moduleName}.service.I${className}Service;

/**
* ${comments}
Expand All @@ -23,22 +22,15 @@ import ${package}.${moduleName}.service.${className}Service;
*/
@Slf4j
@Service
public class ${className}ServiceImpl extends ServiceImpl<${className}Mapper, ${className}> implements I${className}Service {
public class ${className}ServiceImpl extends SuperServiceImpl<${className}Mapper, ${className}> implements I${className}Service {
/**
* 列表
* @param params
* @return
*/
@Override
public PageResult<${className}> findList(Map<String, Object> params){
Integer curPage = MapUtils.getInteger(params, "page");
Integer limit = MapUtils.getInteger(params, "limit");
if (curPage == null) {
curPage = 1;
}
if (limit == null) {
limit = -1;
}
Page<${className}> page = new Page<>(curPage, limit);
Page<${className}> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
List<${className}> list = baseMapper.findList(page, params);
return PageResult.<${className}>builder().data(list).code(0).count(page.getTotal()).build();
}
Expand Down

0 comments on commit 2c6c24b

Please sign in to comment.