开发神器EasyCode( 二 )

<>(true,StatusCode.OK,"查询成功",result);}return new Result<>(true,StatusCode.ERROR,"查询失败");}/*** 新增一条数据** @param $!tool.firstLowerCase($tableInfo.name) 实体类* @return Result对象*/@PostMapping(value = "/insert")public Result insert(@RequestBody $tableInfo.name $!tool.firstLowerCase($tableInfo.name)) {int result = $!{tool.firstLowerCase($tableInfo.name)}ServiceImpl.insert($!tool.firstLowerCase($tableInfo.name));if (result > 0) {return new Result<>(true,StatusCode.OK,"新增成功",result);}return new Result<>(true,StatusCode.ERROR,"新增失败");}/*** 修改一条数据** @param $!tool.firstLowerCase($tableInfo.name) 实体类* @return Result对象*/@PutMapping(value = "/update")public Result update(@RequestBody $tableInfo.name $!tool.firstLowerCase($tableInfo.name)) {$tableInfo.name result = $!{tool.firstLowerCase($tableInfo.name)}ServiceImpl.update($!tool.firstLowerCase($tableInfo.name));if (Objects.nonNull(result)) {return new Result<>(true,StatusCode.OK,"修改成功",result);}return new Result<>(true,StatusCode.ERROR,"修改失败");}/*** 删除一条数据** @param $!pk.name 主键* @return Result对象*/@DeleteMapping(value = "/delete/{$!pk.name}")public Result delete(@PathVariable("$!pk.name") $!pk.shortType $!pk.name) {int result = $!{tool.firstLowerCase($tableInfo.name)}ServiceImpl.deleteById($!pk.name);if (result > 0) {return new Result<>(true,StatusCode.OK,"删除成功",result);}return new Result<>(true,StatusCode.ERROR,"删除失败");}/*** 查询全部** @return Result对象*/@GetMapping(value = "/selectAll")public Result> selectAll() {List<$tableInfo.name> $!tool.firstLowerCase($tableInfo.name)s = $!{tool.firstLowerCase($tableInfo.name)}ServiceImpl.selectAll();if (CollectionUtils.isEmpty($!tool.firstLowerCase($tableInfo.name)s)) {return new Result<>(true,StatusCode.ERROR,"查询全部数据失败");}return new Result<>(true,StatusCode.OK,"查询全部数据成功",$!tool.firstLowerCase($tableInfo.name)s);}/*** 分页查询** @param current 当前页第零页和第一页的数据是一样* @param size 每一页的数据条数* @return Result对象*/@GetMapping(value = "/selectPage/{current}/{size}")public Result selectPage(@PathVariable("current") Integer current,@PathVariable("size") Integer size) {PageInfo<$tableInfo.name> page = $!{tool.firstLowerCase($tableInfo.name)}ServiceImpl.selectPage(current, size);if (Objects.nonNull(page)) {return new Result<>(true,StatusCode.OK,"分页条件查询成功",new PageResult<>(page.getTotal(),page.getList()));}return new Result<>(true,StatusCode.ERROR,"分页查询数据失败");}}service接口:service.java 代码如下:
##定义初始变量#set($tableName = $tool.append($tableInfo.name, "Service"))##设置回调$!callback.setFileName($tool.append($tableName, ".java"))$!callback.setSavePath($tool.append($tableInfo.savePath, "/service"))##拿到主键#if(!$tableInfo.pkColumn.isEmpty())#set($pk = $tableInfo.pkColumn.get(0))#end#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service;import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};import java.util.List;import com.github.pagehelper.PageInfo;/** * $!{tableInfo.comment}($!{tableInfo.name})表服务接口 * * @author protagonist * @since $!time.currTime() */public interface $!{tableName} {/*** 通过ID查询单条数据** @param $!pk.name 主键* @return 实例对象*/$!{tableInfo.name} selectById($!pk.shortType $!pk.name);/*** 分页查询** @param current 当前页* @param size 每一页数据的条数* @return 对象列表*/PageInfo<$!{tableInfo.name}> selectPage(int current, int size);/*** 查询全部** @return 对象列表*/List<$!{tableInfo.name}> selectAll();/*** 通过实体作为筛选条件查询** @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象* @return 对象列表*/List<$!{tableInfo.name}> selectList($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));/*** 新增数据** @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象* @return 影响行数*/int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));/*** 批量新增** @param $!tool.firstLowerCase($!{tableInfo.name})s 实例对象的集合* @return 影响行数*/int batchInsert(List<$!{tableInfo.name}> $!tool.firstLowerCase($!{tableInfo.name})s);/*** 修改数据** @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象* @return 修改*/$!{tableInfo.name} update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));/*** 通过主键删除数据** @param $!pk.name 主键* @return 影响行数*/int deleteById($!pk.shortType $!pk.name);/*** 查询总数据数** @return 数据总数*/int count();}serviceImpl 实现类:serviceImpl .java代码如下:
##定义初始变量#set($tableName = $tool.append($tableInfo.name, "ServiceImpl"))##设置回调$!callback.setFileName($tool.append($tableName, ".java"))$!callback.setSavePath($tool.append($tableInfo.savePath, "/service/impl"))##拿到主键#if(!$tableInfo.pkColumn.isEmpty())#set($pk = $tableInfo.pkColumn.get(0))#end#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service.impl;import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};import $!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Dao;import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;import org.springframework.transaction.annotation.Transactional;import org.springframework.stereotype.Service;import com.github.pagehelper.PageHelper;import com.github.pagehelper.PageInfo;import javax.annotation.Resource;import java.util.List;/** * $!{tableInfo.comment}($!{tableInfo.name}表)服务实现类 * * @author protagonist * @since $!time.currTime() */@Service("$!tool.firstLowerCase($!{tableInfo.name})ServiceImpl")public class $!{tableName} implements $!{tableInfo.name}Service {@Resourceprivate $!{tableInfo.name}Dao $!tool.firstLowerCase($!{tableInfo.name})Dao;/*** 通过ID查询单条数据** @param $!pk.name 主键* @return 实例对象*/@Overridepublic $!{tableInfo.name} selectById($!pk.shortType $!pk.name) {return this.$!{tool.firstLowerCase($!{tableInfo.name})}Dao.selectById($!pk.name);}/*** 分页查询** @param current 当前页* @param size 每一页的条数* @return 对象列表*/@Overridepublic PageInfo<$!{tableInfo.name}> selectPage(int current, int size) {PageHelper.startPage(current,size);List<$!{tableInfo.name}> dataList = $!{tool.firstLowerCase($!{tableInfo.name})}Dao.selectAll();return new PageInfo<>(dataList);}/*** 查询所有** @return 实例对象的集合*/@Overridepublic List<$!{tableInfo.name}> selectAll() {return this.$!{tool.firstLowerCase($!{tableInfo.name})}Dao.selectAll();}/*** 根据条件查询** @return 实例对象的集合*/@Overridepublic List<$!{tableInfo.name}> selectList($!{tableInfo.name} $!{tool.firstLowerCase($!{tableInfo.name})}) {return this.$!{tool.firstLowerCase($!{tableInfo.name})}Dao.selectList($!{tool.firstLowerCase($!{tableInfo.name})});}/*** 新增数据** @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象* @return 实例对象*/@Override@Transactionalpublic int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {return this.$!{tool.firstLowerCase($!{tableInfo.name})}Dao.insert($!tool.firstLowerCase($!{tableInfo.name}));}/*** 批量新增** @param $!tool.firstLowerCase($!{tableInfo.name})s 实例对象的集合* @return 生效的条数*/@Override@Transactionalpublic int batchInsert(List<$!{tableInfo.name}> $!tool.firstLowerCase($!{tableInfo.name})s) {return this.$!{tool.firstLowerCase($!{tableInfo.name})}Dao.batchInsert($!tool.firstLowerCase($!{tableInfo.name})s);}/*** 修改数据** @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象* @return 实例对象*/@Override@Transactionalpublic $!{tableInfo.name} update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {this.$!{tool.firstLowerCase($!{tableInfo.name})}Dao.update($!tool.firstLowerCase($!{tableInfo.name}));return this.selectById($!{tool.firstLowerCase($!{tableInfo.name})}.get$!tool.firstUpperCase($pk.name)());}/*** 通过主键删除数据** @param $!pk.name 主键* @return 是否成功*/@Override@Transactionalpublic int deleteById($!pk.shortType $!pk.name) {return this.$!{tool.firstLowerCase($!{tableInfo.name})}Dao.deleteById($!pk.name);}/*** 查询总数据数** @return 数据总数*/@Overridepublic int count(){return this.$!{tool.firstLowerCase($!{tableInfo.name})}Dao.count();}}


推荐阅读