From 63d393fa8ffbe442feb83490d70e33c39924cfc0 Mon Sep 17 00:00:00 2001 From: StevenGuo Date: Wed, 15 May 2019 11:27:47 +0800 Subject: [PATCH 1/3] [UPD] --- SpringBootCodeGenerator.iml | 70 ---------------- generator-web/generator-web.iml | 84 ------------------- .../code-generator/mybatis/controller.ftl | 1 + 3 files changed, 1 insertion(+), 154 deletions(-) delete mode 100644 SpringBootCodeGenerator.iml delete mode 100644 generator-web/generator-web.iml diff --git a/SpringBootCodeGenerator.iml b/SpringBootCodeGenerator.iml deleted file mode 100644 index e67ee345..00000000 --- a/SpringBootCodeGenerator.iml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/generator-web/generator-web.iml b/generator-web/generator-web.iml deleted file mode 100644 index 6b33a9b7..00000000 --- a/generator-web/generator-web.iml +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl index d8b52a22..c342868b 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl @@ -21,6 +21,7 @@ public class ${classInfo.className}Controller { /** * 新增 */ + @RequestMapping("/insert") @ResponseBody public ReturnT insert(${classInfo.className} ${classInfo.className?uncap_first}){ From 1a4b3017c4ed378029545df40e03cd16906cbfd2 Mon Sep 17 00:00:00 2001 From: StevenGuo Date: Thu, 16 May 2019 18:02:46 +0800 Subject: [PATCH 2/3] =?UTF-8?q?[UPD]=201.=E4=BC=98=E5=8C=96=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=201.0=202.=E4=BF=AE=E6=94=B9=20mybatis=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E4=B8=AD=20controller=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../code-generator/mybatis/controller.ftl | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl index c342868b..feb665cc 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl @@ -10,38 +10,42 @@ import java.util.Map; /** * ${classInfo.classComment} -* @author ${authorName} ${.now?string('yyyy-MM-dd')} +* @author ${authorName} +* @date ${.now?string('yyyy/MM/dd')} */ -@Controller +@RestController +@RequestMapping(value = "/${classInfo.className}") public class ${classInfo.className}Controller { @Resource private ${classInfo.className}Service ${classInfo.className?uncap_first}Service; /** - * 新增 - */ - + * [新增] + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ @RequestMapping("/insert") - @ResponseBody public ReturnT insert(${classInfo.className} ${classInfo.className?uncap_first}){ return ${classInfo.className?uncap_first}Service.insert(${classInfo.className?uncap_first}); } /** - * 删除 - */ + * [刪除] + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ @RequestMapping("/delete") - @ResponseBody public ReturnT delete(int id){ return ${classInfo.className?uncap_first}Service.delete(id); } /** - * 更新 - */ + * [更新] + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ @RequestMapping("/update") - @ResponseBody public ReturnT update(${classInfo.className} ${classInfo.className?uncap_first}){ return ${classInfo.className?uncap_first}Service.update(${classInfo.className?uncap_first}); } @@ -50,7 +54,6 @@ public class ${classInfo.className}Controller { * Load查询 */ @RequestMapping("/load") - @ResponseBody public ReturnT load(int id){ return ${classInfo.className?uncap_first}Service.load(id); } @@ -59,7 +62,6 @@ public class ${classInfo.className}Controller { * 分页查询 */ @RequestMapping("/pageList") - @ResponseBody public Map pageList(@RequestParam(required = false, defaultValue = "0") int offset, @RequestParam(required = false, defaultValue = "10") int pagesize) { return ${classInfo.className?uncap_first}Service.pageList(offset, pagesize); From d7cbe49b87437a403276763a36533d6c392deb93 Mon Sep 17 00:00:00 2001 From: StevenGuo Date: Fri, 17 May 2019 11:28:44 +0800 Subject: [PATCH 3/3] =?UTF-8?q?[UPD]=201.=E4=BC=98=E5=8C=96=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=202.=E4=BF=AE=E6=94=B9=20mybatis=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E4=B8=AD=20controller=E6=B3=A8=E8=A7=A3=203.=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=20mybatis=E6=A8=A1=E6=9D=BF=E4=B8=AD=20dao=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E4=B8=BA=20mapper=E6=96=87=E4=BB=B6=204.?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=20mybatis=E6=A8=A1=E6=9D=BF=E4=B8=AD=20servi?= =?UTF-8?q?ce=E5=AE=9E=E7=8E=B0=E7=B1=BB=E4=B8=AD=E7=9A=84=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=20bug=205.=E4=BF=AE=E6=94=B9=20index.ftl=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=AD=20mybatis=E6=A8=A1=E6=9D=BF=E7=9A=84=20dao?= =?UTF-8?q?=20->=20mapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../code-generator/mybatis/controller.ftl | 12 ++-- .../templates/code-generator/mybatis/dao.ftl | 49 --------------- .../code-generator/mybatis/mapper.ftl | 60 +++++++++++++++++++ .../code-generator/mybatis/service.ftl | 5 +- .../code-generator/mybatis/service_impl.ftl | 41 +++++-------- .../src/main/resources/templates/index.ftl | 2 +- 6 files changed, 88 insertions(+), 81 deletions(-) delete mode 100644 generator-web/src/main/resources/templates/code-generator/mybatis/dao.ftl create mode 100644 generator-web/src/main/resources/templates/code-generator/mybatis/mapper.ftl diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl index feb665cc..400aa888 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl @@ -51,16 +51,20 @@ public class ${classInfo.className}Controller { } /** - * Load查询 - */ + * [查詢] 根據主鍵 id 查詢 + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ @RequestMapping("/load") public ReturnT load(int id){ return ${classInfo.className?uncap_first}Service.load(id); } /** - * 分页查询 - */ + * [查詢] 分頁查詢 + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ @RequestMapping("/pageList") public Map pageList(@RequestParam(required = false, defaultValue = "0") int offset, @RequestParam(required = false, defaultValue = "10") int pagesize) { diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/dao.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/dao.ftl deleted file mode 100644 index cc602106..00000000 --- a/generator-web/src/main/resources/templates/code-generator/mybatis/dao.ftl +++ /dev/null @@ -1,49 +0,0 @@ -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Component; - -import java.util.List; - -/** -* ${classInfo.classComment} -* @author ${authorName} ${.now?string('yyyy-MM-dd')} -*/ -@Repository -public interface ${classInfo.className}Dao { - - /** - * 新增 - * @param ${classInfo.className}Entity - */ - public Integer insert(@Param("${classInfo.className?uncap_first}") ${classInfo.className}Entity ${classInfo.className?uncap_first}); - - /** - * 删除 - * @param id - */ - public Integer delete(@Param("id") Integer id); - - /** - * 更新 - * @param ${classInfo.className}Entity - */ - public Integer update(@Param("${classInfo.className?uncap_first}") ${classInfo.className}Entity ${classInfo.className?uncap_first}); - - /** - * 根据主键查询一个实体 - * @param id - */ - public ${classInfo.className}Entity selectByPrimaryKey(@Param("id") Integer id); - - /** - * 分页查询Data - * @param offset - * @param pageSize - */ - public List<${classInfo.className}Entity> pageList(@Param("offset") Integer offset, @Param("pageSize") Integer pageSize); - - /** - * 分页查询Count - */ - public Integer pageListCount(); - -} \ No newline at end of file diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/mapper.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/mapper.ftl new file mode 100644 index 00000000..6a01e2bf --- /dev/null +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/mapper.ftl @@ -0,0 +1,60 @@ +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; +import java.util.List; + +/** +* ${classInfo.classComment} +* @author ${authorName} +* @date ${.now?string('yyyy/MM/dd')} +*/ +@Mapper +@Repository +public interface ${classInfo.className}Mapper { + + /** + * [新增] + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ + int insert(@Param("${classInfo.className?uncap_first}") ${classInfo.className} ${classInfo.className?uncap_first}); + + /** + * [刪除] + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ + int delete(@Param("id") int id); + + /** + * [更新] + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ + int update(@Param("${classInfo.className?uncap_first}") ${classInfo.className} ${classInfo.className?uncap_first}); + + /** + * [查詢] 根據主鍵 id 查詢 + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ + ${classInfo.className} load(@Param("id") int id); + + /** + * [查詢] 分頁查詢 + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ + List<${classInfo.className}> pageList(@Param("offset") int offset, + @Param("pagesize") int pagesize); + + /** + * [查詢] 分頁查詢 count + * @author ${authorName} + * @date ${.now?string('yyyy/MM/dd')} + **/ + int pageListCount(@Param("offset") int offset, + @Param("pagesize") int pagesize); + +} diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/service.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/service.ftl index 3de47531..11718e01 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis/service.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/service.ftl @@ -2,7 +2,8 @@ import java.util.Map; /** * ${classInfo.classComment} -* @author ${authorName} ${.now?string('yyyy-MM-dd')} +* @author ${authorName} +* @date ${.now?string('yyyy/MM/dd')} */ public interface ${classInfo.className}Service { @@ -22,7 +23,7 @@ public interface ${classInfo.className}Service { public ReturnT update(${classInfo.className} ${classInfo.className?uncap_first}); /** - * Load查询 + * 根據主鍵 id 查詢 */ public ${classInfo.className} load(int id); diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/service_impl.ftl b/generator-web/src/main/resources/templates/code-generator/mybatis/service_impl.ftl index 8bb37a65..a5d6e89d 100644 --- a/generator-web/src/main/resources/templates/code-generator/mybatis/service_impl.ftl +++ b/generator-web/src/main/resources/templates/code-generator/mybatis/service_impl.ftl @@ -8,17 +8,16 @@ import java.util.Map; /** * ${classInfo.classComment} -* @author ${authorName} ${.now?string('yyyy-MM-dd')} +* @author ${authorName} +* @date ${.now?string('yyyy/MM/dd')} */ @Service public class ${classInfo.className}ServiceImpl implements ${classInfo.className}Service { @Resource - private ${classInfo.className}Dao ${classInfo.className?uncap_first}Dao; + private ${classInfo.className}Mapper ${classInfo.className?uncap_first}Mapper; + - /** - * 新增 - */ @Override public ReturnT insert(${classInfo.className} ${classInfo.className?uncap_first}) { @@ -27,49 +26,41 @@ public class ${classInfo.className}ServiceImpl implements ${classInfo.className} return new ReturnT(ReturnT.FAIL_CODE, "必要参数缺失"); } - ${classInfo.className?uncap_first}Dao.insert(${classInfo.className?uncap_first}); + ${classInfo.className?uncap_first}Mapper.insert(${classInfo.className?uncap_first}); return ReturnT.SUCCESS; } - /** - * 删除 - */ + @Override public ReturnT delete(int id) { - int ret = ${classInfo.className?uncap_first}Dao.delete(id); + int ret = ${classInfo.className?uncap_first}Mapper.delete(id); return ret>0?ReturnT.SUCCESS:ReturnT.FAIL; } - /** - * 更新 - */ + @Override public ReturnT update(${classInfo.className} ${classInfo.className?uncap_first}) { - int ret = ${classInfo.className?uncap_first}Dao.update(${classInfo.className?uncap_first}); + int ret = ${classInfo.className?uncap_first}Mapper.update(${classInfo.className?uncap_first}); return ret>0?ReturnT.SUCCESS:ReturnT.FAIL; } - /** - * Load查询 - */ + @Override public ${classInfo.className} load(int id) { - return ${classInfo.className?uncap_first}Dao.load(id); + return ${classInfo.className?uncap_first}Mapper.load(id); } - /** - * 分页查询 - */ + @Override public Map pageList(int offset, int pagesize) { - List<${classInfo.className}> pageList = ${classInfo.className?uncap_first}Dao.pageList(offset, pagesize); - int totalCount = ${classInfo.className?uncap_first}Dao.pageListCount(offset, pagesize); + List<${classInfo.className}> pageList = ${classInfo.className?uncap_first}Mapper.pageList(offset, pagesize); + int totalCount = ${classInfo.className?uncap_first}Mapper.pageListCount(offset, pagesize); // result Map result = new HashMap(); - maps.put("pageList", pageList); - maps.put("totalCount", totalCount); + result.put("pageList", pageList); + result.put("totalCount", totalCount); return result; } diff --git a/generator-web/src/main/resources/templates/index.ftl b/generator-web/src/main/resources/templates/index.ftl index 5ca66f99..2a98e672 100644 --- a/generator-web/src/main/resources/templates/index.ftl +++ b/generator-web/src/main/resources/templates/index.ftl @@ -156,7 +156,7 @@ CREATE TABLE `userinfo` (
- +