手记系列之二 ----- 关于IDEA的一些使用方法经验( 四 )

3.service模板
PowerShell##定义初始变量#set($tableName = $tool.append("I",$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;$!autoImportimport $!{tableInfo.savePackageName}.vo.$!{tableInfo.name}VO;import java.util.List; /*** @Title: $!{tableInfo.comment}($!{tableInfo.name})表服务接口* @Description: * @Version:1.0.0 * @Since:jdk1.8 * @author $author* @date $!time.currTime()*/public interface $!{tableName} {/*** 通过ID查询单条数据** @param $!pk.name 主键* @return 实例对象*/$!{tableInfo.name}VO queryById($!pk.shortType $!pk.name);/*** 通过实体作为筛选条件查询** @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象* @return 对象列表*/ApiResult list($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO);/*** 新增数据** @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象* @return 实例对象*/int insert($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO);/*** 修改数据** @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象* @return 实例对象*/int update($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO);/*** 通过主键删除数据** @param $!pk.name 主键* @return 是否成功*/boolean deleteById($!pk.shortType $!pk.name);}4.serviceImpl 模板
PowerShell##定义初始变量#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;$!autoImportimport $!{tableInfo.savePackageName}.vo.$!{tableInfo.name}VO;import $!{tableInfo.savePackageName}.model.$!{tableInfo.name};import $!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Dao;import $!{tableInfo.savePackageName}.service.I$!{tableInfo.name}Service;import com.github.pagehelper.Page;import com.github.pagehelper.PageHelper;import org.springframework.stereotype.Service;import org.springframework.beans.BeanUtils;import javax.annotation.Resource;import java.util.List;/*** @Title: $!{tableInfo.comment}($!{tableInfo.name})表服务实现类* @Description: * @Version:1.0.0 * @Since:jdk1.8 * @author $author* @date $!time.currTime()*/@Service("$!tool.firstLowerCase($!{tableInfo.name})Service")public class $!{tableName} implements I$!{tableInfo.name}Service {@Resourceprivate $!{tableInfo.name}Dao $!tool.firstLowerCase($!{tableInfo.name})Dao;/*** 通过ID查询单条数据** @param $!pk.name 主键* @return 实例对象*/@Overridepublic $!{tableInfo.name}VO queryById($!pk.shortType $!pk.name) {return this.$!{tool.firstLowerCase($!{tableInfo.name})}Dao.queryById($!pk.name);}/*** 根据条件查询** @return 实例对象的集合*/@Overridepublic ApiResult list($!{tableInfo.name}VO $!{tool.firstLowerCase($!{tableInfo.name})}) {int pageNum = $!{tool.firstLowerCase($!{tableInfo.name})}.getPageNum();int pageSize = $!{tool.firstLowerCase($!{tableInfo.name})}.getPageSize();Page page = PageHelper.startPage(pageNum, pageSize);List<$!{tableInfo.name}VO> result =$!{tool.firstLowerCase($!{tableInfo.name})}Dao.queryAll($!{tool.firstLowerCase($!{tableInfo.name})});return ApiResult.success(new PageResult<>(page.getTotal(), result, pageSize, pageNum));}/*** 新增数据** @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象* @return 实例对象*/@Overridepublic int insert($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO) {$!{tableInfo.name}$!tool.firstLowerCase($!{tableInfo.name}) = new $!{tableInfo.name}();BeanUtils.copyProperties($!tool.firstLowerCase($!{tableInfo.name})VO,$!tool.firstLowerCase($!{tableInfo.name}));return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.insert($!tool.firstLowerCase($!{tableInfo.name}));}/*** 修改数据** @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象* @return 实例对象*/@Overridepublic int update($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO) {$!{tableInfo.name}$!tool.firstLowerCase($!{tableInfo.name}) = new $!{tableInfo.name}();BeanUtils.copyProperties($!tool.firstLowerCase($!{tableInfo.name})VO,$!tool.firstLowerCase($!{tableInfo.name}));return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.update($!tool.firstLowerCase($!{tableInfo.name}));}/*** 通过主键删除数据** @param $!pk.name 主键* @return 是否成功*/@Overridepublic boolean deleteById($!pk.shortType $!pk.name) {return this.$!{tool.firstLowerCase($!{tableInfo.name})}Dao.deleteById($!pk.name) > 0;}}5.controller模板
Kotlin##定义初始变量#set($tableName = $tool.append($tableInfo.name, "Controller"))##设置回调$!callback.setFileName($tool.append($tableName, ".java"))$!callback.setSavePath($tool.append($tableInfo.savePath, "/controller"))##拿到主键#if(!$tableInfo.pkColumn.isEmpty())#set($pk = $tableInfo.pkColumn.get(0))#end#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller;import $!{tableInfo.savePackageName}.vo.$!{tableInfo.name}VO;import $!{tableInfo.savePackageName}.service.I$!{tableInfo.name}Service;import org.springframework.web.bind.annotation.*;import io.swagger.annotations.Api;import io.swagger.annotations.ApiOperation;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.RequestBody;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RestController;import javax.servlet.http.HttpServletRequest;/*** @Title: $!{tableInfo.comment}($!{tableInfo.name})表控制层* @Description: * @Version:1.0.0 * @Since:jdk1.8 * @author $author* @date $!time.currTime()*/@Api(tags = "$!{tableInfo.comment}($!{tableInfo.name})")@RestController@RequestMapping("$!tool.firstLowerCase($tableInfo.name)")public class $!{tableName} {/*** 服务对象*/@Autowiredprivate I$!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;/*** 新增一条数据** @param $!tool.firstLowerCase($tableInfo.name)VO 实体类* @return Response对象*/@ApiOperation(value = "https://www.huyubaike.com/biancheng/$!{tableInfo.comment}新增",notes = "$!{tableInfo.comment}新增")@RequestMapping(value = "https://www.huyubaike.com/biancheng/save", method = RequestMethod.POST)public ApiResult insert(@RequestBody $!{tableInfo.name}VO $!tool.firstLowerCase($tableInfo.name)VO, HttpServletRequest httpRequest) {int result = $!{tool.firstLowerCase($tableInfo.name)}Service.insert($!tool.firstLowerCase($tableInfo.name)VO);if (result > 0) {return ApiResult.success();}return ApiResult.error("新增失败");}/*** 修改一条数据** @param $!tool.firstLowerCase($tableInfo.name)VO 实体类* @return Response对象*/@ApiOperation(value = "https://www.huyubaike.com/biancheng/$!{tableInfo.comment}修改",notes = "$!{tableInfo.comment}修改")@RequestMapping(value = "https://www.huyubaike.com/biancheng/edit", method = RequestMethod.POST)public ApiResult update(@RequestBody $!{tableInfo.name}VO $!tool.firstLowerCase($tableInfo.name)VO, HttpServletRequest httpRequest) {$!{tool.firstLowerCase($tableInfo.name)}Service.update($!tool.firstLowerCase($tableInfo.name)VO);return ApiResult.success();}/*** 删除一条数据** @param $!tool.firstLowerCase($tableInfo.name)VO 参数对象* @return Response对象*/@ApiOperation(value = "https://www.huyubaike.com/biancheng/$!{tableInfo.comment}删除",notes = "$!{tableInfo.comment}删除")@RequestMapping(value = "https://www.huyubaike.com/biancheng/del", method = RequestMethod.POST)public ApiResult delete(@RequestBody $!{tableInfo.name}VO $!tool.firstLowerCase($tableInfo.name)VO, HttpServletRequest httpRequest) {$!{tool.firstLowerCase($tableInfo.name)}Service.deleteById($!{tool.firstLowerCase($tableInfo.name)}VO.getId());return ApiResult.success();}/*** 分页查询**/@ApiOperation(value = "https://www.huyubaike.com/biancheng/$!{tableInfo.comment}查询",notes = "$!{tableInfo.comment}查询")@RequestMapping(value = "https://www.huyubaike.com/biancheng/list", method = RequestMethod.POST)public ApiResult list(@RequestBody $!{tableInfo.name}VO $!tool.firstLowerCase($tableInfo.name)VO) {return$!{tool.firstLowerCase($tableInfo.name)}Service.list($!tool.firstLowerCase($tableInfo.name)VO);}/*** 详情查询**/@ApiOperation(value = "https://www.huyubaike.com/biancheng/$!{tableInfo.comment}详情",notes = "$!{tableInfo.comment}详情")@RequestMapping(value = "https://www.huyubaike.com/biancheng/view", method = RequestMethod.GET)public ApiResult view( @RequestParam("id") Long id) {return ApiResult.success($!{tool.firstLowerCase($tableInfo.name)}Service.queryById(id));}}

推荐阅读