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

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));}}

经验总结扩展阅读