From c537f9d5c0f13cd9d376f1eb5cb73989bf6b9d9e Mon Sep 17 00:00:00 2001 From: xuwujing <1060589146@qq.com> Date: Mon, 1 Apr 2024 09:55:35 +0800 Subject: [PATCH] update EasyCode --- springboot-demo/easycode/EasyCodeConfig.json | 90 +++++++++++- springboot-demo/pom.xml | 5 + .../pancm/controller/TSysUserController.java | 103 ++++++++++++++ .../main/java/com/pancm/dao/TSysUserDao.java | 87 ++++++++++++ .../src/main/java/com/pancm/dao/UserDao.java | 4 +- .../main/java/com/pancm/model/TSysUser.java | 61 +++++++++ .../com/pancm/service/ITSysUserService.java | 62 +++++++++ .../service/impl/TSysUserServiceImpl.java | 97 +++++++++++++ .../main/java/com/pancm/vo/TSysUserVO.java | 61 +++++++++ .../resources/pancm/mapper/TSysUserMapper.xml | 128 ++++++++++++++++++ 10 files changed, 695 insertions(+), 3 deletions(-) create mode 100644 springboot-demo/src/main/java/com/pancm/controller/TSysUserController.java create mode 100644 springboot-demo/src/main/java/com/pancm/dao/TSysUserDao.java create mode 100644 springboot-demo/src/main/java/com/pancm/model/TSysUser.java create mode 100644 springboot-demo/src/main/java/com/pancm/service/ITSysUserService.java create mode 100644 springboot-demo/src/main/java/com/pancm/service/impl/TSysUserServiceImpl.java create mode 100644 springboot-demo/src/main/java/com/pancm/vo/TSysUserVO.java create mode 100644 springboot-demo/src/main/resources/pancm/mapper/TSysUserMapper.xml diff --git a/springboot-demo/easycode/EasyCodeConfig.json b/springboot-demo/easycode/EasyCodeConfig.json index a176c05..8f4740b 100644 --- a/springboot-demo/easycode/EasyCodeConfig.json +++ b/springboot-demo/easycode/EasyCodeConfig.json @@ -3,10 +3,71 @@ "version" : "1.2.8", "userSecure" : "", "currTypeMapperGroupName" : "Default", - "currTemplateGroupName" : "pancm", + "currTemplateGroupName" : "pancm_mybatis_plus", "currColumnConfigGroupName" : "Default", "currGlobalConfigGroupName" : "Default", - "typeMapper" : { }, + "typeMapper" : { + "Default" : { + "name" : "Default", + "elementList" : [ { + "matchType" : "REGEX", + "columnType" : "varchar(\\(\\d+\\))?", + "javaType" : "java.lang.String" + }, { + "matchType" : "REGEX", + "columnType" : "char(\\(\\d+\\))?", + "javaType" : "java.lang.String" + }, { + "matchType" : "REGEX", + "columnType" : "(tiny|medium|long)*text", + "javaType" : "java.lang.String" + }, { + "matchType" : "REGEX", + "columnType" : "decimal(\\(\\d+,\\d+\\))?", + "javaType" : "java.lang.Double" + }, { + "matchType" : "ORDINARY", + "columnType" : "integer", + "javaType" : "java.lang.Integer" + }, { + "matchType" : "REGEX", + "columnType" : "(tiny|small|medium)*int(\\(\\d+\\))?", + "javaType" : "java.lang.Integer" + }, { + "matchType" : "ORDINARY", + "columnType" : "int4", + "javaType" : "java.lang.Integer" + }, { + "matchType" : "ORDINARY", + "columnType" : "int8", + "javaType" : "java.lang.Long" + }, { + "matchType" : "REGEX", + "columnType" : "bigint(\\(\\d+\\))?", + "javaType" : "java.lang.Long" + }, { + "matchType" : "ORDINARY", + "columnType" : "date", + "javaType" : "java.util.Date" + }, { + "matchType" : "ORDINARY", + "columnType" : "datetime", + "javaType" : "java.util.Date" + }, { + "matchType" : "ORDINARY", + "columnType" : "timestamp", + "javaType" : "java.util.Date" + }, { + "matchType" : "ORDINARY", + "columnType" : "time", + "javaType" : "java.time.LocalTime" + }, { + "matchType" : "ORDINARY", + "columnType" : "boolean", + "javaType" : "java.lang.Boolean" + } ] + } + }, "template" : { "pancm" : { "name" : "pancm", @@ -32,6 +93,31 @@ "name" : "mapper.xml.vm", "code" : "##引入mybatis支持\n$!{mybatisSupport.vm}\n\n##设置保存名称与保存位置\n$!callback.setFileName($tool.append($!{tableInfo.name}, \"Mapper.xml\"))\n$!callback.setSavePath($tool.append($modulePath, \"/src/main/resources/pancm/mapper\"))\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n\n\n\n\n \n#foreach($column in $tableInfo.fullColumn)\n \n#end\n \n\n \n \n \n \n \n\n \n \n\n \n \n insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($foreach.hasNext), #end#end)\n values (#foreach($column in $tableInfo.otherColumn)#{$!{column.name}}#if($foreach.hasNext), #end#end)\n \n\n \n insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($foreach.hasNext), #end#end)\n values\n \n (#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($foreach.hasNext), #end#end)\n \n \n\n \n insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($foreach.hasNext), #end#end)\n values\n \n (#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($foreach.hasNext), #end#end)\n \n on duplicate key update\n #foreach($column in $tableInfo.otherColumn)$!column.obj.name = values($!column.obj.name) #if($foreach.hasNext), #end#end\n \n\n \n \n update $!{tableInfo.obj.name}\n \n#foreach($column in $tableInfo.otherColumn)\n \n $!column.obj.name = #{$!column.name},\n \n#end\n \n where $!pk.obj.name = #{$!pk.name}\n \n\n \n \n delete from $!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name}\n \n\n\n" } ] + }, + "pancm_mybatis_plus" : { + "name" : "pancm_mybatis_plus", + "elementList" : [ { + "name" : "controller.java", + "code" : "##定义初始变量\n#set($tableName = $tool.append($tableInfo.name, \"Controller\"))\n##设置回调\n$!callback.setFileName($tool.append($tableName, \".java\"))\n$!callback.setSavePath($tool.append($tableInfo.savePath, \"/controller\"))\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller;\n\nimport $!{tableInfo.savePackageName}.vo.$!{tableInfo.name}VO;\nimport $!{tableInfo.savePackageName}.service.I$!{tableInfo.name}Service;\nimport org.springframework.web.bind.annotation.*;\n\n\nimport com.pancm.vo.ApiResult;\nimport io.swagger.annotations.Api;\nimport io.swagger.annotations.ApiOperation;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.web.bind.annotation.RequestBody;\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RequestMethod;\nimport org.springframework.web.bind.annotation.RestController;\n\nimport javax.servlet.http.HttpServletRequest;\n\n\n\n/**\n* @Title: $!{tableInfo.comment}($!{tableInfo.name})表控制层\n* @Description: \n* @Version:1.0.0 \n* @Since:jdk1.8 \n* @author $author\n* @date $!time.currTime()\n*/\n@Api(tags = \"$!{tableInfo.comment}($!{tableInfo.name})\")\n@RestController\n@RequestMapping(\"$!tool.firstLowerCase($tableInfo.name)\")\npublic class $!{tableName} {\n /**\n * 服务对象\n */\n @Autowired\n private I$!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;\n\n\n /**\n * 新增一条数据\n *\n * @param $!tool.firstLowerCase($tableInfo.name)VO 实体类\n * @return Response对象\n */\n @ApiOperation(value = \"$!{tableInfo.comment}新增\",notes = \"$!{tableInfo.comment}新增\")\n @RequestMapping(value = \"save\", method = RequestMethod.POST)\n public ApiResult insert(@RequestBody $!{tableInfo.name}VO $!tool.firstLowerCase($tableInfo.name)VO, HttpServletRequest httpRequest) {\n int result = $!{tool.firstLowerCase($tableInfo.name)}Service.insert($!tool.firstLowerCase($tableInfo.name)VO);\n if (result > 0) {\n return ApiResult.success();\n }\n return ApiResult.error(\"新增失败\");\n }\n\n /**\n * 修改一条数据\n *\n * @param $!tool.firstLowerCase($tableInfo.name)VO 实体类\n * @return Response对象\n */\n @ApiOperation(value = \"$!{tableInfo.comment}修改\",notes = \"$!{tableInfo.comment}修改\")\n @RequestMapping(value = \"edit\", method = RequestMethod.POST)\n public ApiResult update(@RequestBody $!{tableInfo.name}VO $!tool.firstLowerCase($tableInfo.name)VO, HttpServletRequest httpRequest) {\n $!{tool.firstLowerCase($tableInfo.name)}Service.update($!tool.firstLowerCase($tableInfo.name)VO); \n return ApiResult.success();\n }\n\n /**\n * 删除一条数据\n *\n * @param $!tool.firstLowerCase($tableInfo.name)VO 参数对象\n * @return Response对象\n */\n @ApiOperation(value = \"$!{tableInfo.comment}删除\",notes = \"$!{tableInfo.comment}删除\") \n @RequestMapping(value = \"del\", method = RequestMethod.POST)\n public ApiResult delete(@RequestBody $!{tableInfo.name}VO $!tool.firstLowerCase($tableInfo.name)VO, HttpServletRequest httpRequest) {\n $!{tool.firstLowerCase($tableInfo.name)}Service.deleteById($!{tool.firstLowerCase($tableInfo.name)}VO.getId());\n return ApiResult.success(); \n }\n\n \n\n /**\n * 分页查询\n *\n */\n @ApiOperation(value = \"$!{tableInfo.comment}查询\",notes = \"$!{tableInfo.comment}查询\")\n @RequestMapping(value = \"list\", method = RequestMethod.POST)\n public ApiResult list(@RequestBody $!{tableInfo.name}VO $!tool.firstLowerCase($tableInfo.name)VO) {\n return $!{tool.firstLowerCase($tableInfo.name)}Service.list($!tool.firstLowerCase($tableInfo.name)VO);\n }\n\n /**\n * 详情查询\n *\n */ \n @ApiOperation(value = \"$!{tableInfo.comment}详情\",notes = \"$!{tableInfo.comment}详情\") \n @RequestMapping(value = \"view\", method = RequestMethod.GET)\n public ApiResult view( @RequestParam(\"id\") Long id) {\n return ApiResult.success($!{tool.firstLowerCase($tableInfo.name)}Service.queryById(id)); \n }\n}" + }, { + "name" : "service.java", + "code" : "##定义初始变量\n#set($tableName = $tool.append(\"I\",$tableInfo.name, \"Service\"))\n##设置回调\n$!callback.setFileName($tool.append($tableName, \".java\"))\n$!callback.setSavePath($tool.append($tableInfo.savePath, \"/service\"))\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service;\n$!autoImport\nimport $!{tableInfo.savePackageName}.vo.$!{tableInfo.name}VO;\nimport $!{tableInfo.savePackageName}.model.$!{tableInfo.name};\nimport com.pancm.vo.ApiResult;\nimport java.util.List;\nimport com.baomidou.mybatisplus.extension.service.IService;\n\n\n /**\n* @Title: $!{tableInfo.comment}($!{tableInfo.name})表服务接口\n* @Description: \n* @Version:1.0.0 \n* @Since:jdk1.8 \n* @author $author\n* @date $!time.currTime()\n*/\npublic interface $!{tableName} extends IService<$!tableInfo.name>{\n\n /**\n * 通过ID查询单条数据\n *\n * @param $!pk.name 主键\n * @return 实例对象\n */\n $!{tableInfo.name}VO queryById($!pk.shortType $!pk.name);\n\n \n /**\n * 通过实体作为筛选条件查询\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象\n * @return 对象列表\n */\n ApiResult list($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO);\n\n \n /**\n * 新增数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象\n * @return 实例对象\n */\n int insert($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO);\n\n /**\n * 修改数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象\n * @return 实例对象\n */\n int update($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO);\n\n /**\n * 通过主键删除数据\n *\n * @param $!pk.name 主键\n * @return 是否成功\n */\n boolean deleteById($!pk.shortType $!pk.name);\n\n}" + }, { + "name" : "serviceImpl.java", + "code" : "##定义初始变量\n#set($tableName = $tool.append($tableInfo.name, \"ServiceImpl\"))\n##设置回调\n$!callback.setFileName($tool.append($tableName, \".java\"))\n$!callback.setSavePath($tool.append($tableInfo.savePath, \"/service/impl\"))\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service.impl;\n$!autoImport\n\nimport $!{tableInfo.savePackageName}.vo.$!{tableInfo.name}VO;\nimport $!{tableInfo.savePackageName}.model.$!{tableInfo.name};\nimport $!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Dao;\nimport $!{tableInfo.savePackageName}.service.I$!{tableInfo.name}Service;\n\nimport com.github.pagehelper.Page;\nimport com.github.pagehelper.PageHelper;\nimport com.pancm.vo.ApiResult;\nimport com.pancm.vo.PageResult;\nimport org.springframework.stereotype.Service;\nimport org.springframework.beans.BeanUtils;\nimport javax.annotation.Resource;\nimport java.util.List;\nimport com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;\n\n\n\n/**\n* @Title: $!{tableInfo.comment}($!{tableInfo.name})表服务实现类\n* @Description: \n* @Version:1.0.0 \n* @Since:jdk1.8 \n* @author $author\n* @date $!time.currTime()\n*/\n@Service(\"$!tool.firstLowerCase($!{tableInfo.name})Service\")\npublic class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Dao, $!{tableInfo.name}> implements I$!{tableInfo.name}Service {\n @Resource\n private $!{tableInfo.name}Dao $!tool.firstLowerCase($!{tableInfo.name})Dao;\n\n /**\n * 通过ID查询单条数据\n *\n * @param $!pk.name 主键\n * @return 实例对象\n */\n @Override\n public $!{tableInfo.name}VO queryById($!pk.shortType $!pk.name) {\n return this.$!{tool.firstLowerCase($!{tableInfo.name})}Dao.queryById($!pk.name);\n }\n\n \n /**\n * 根据条件查询\n *\n * @return 实例对象的集合\n */\n @Override\n public ApiResult list($!{tableInfo.name}VO $!{tool.firstLowerCase($!{tableInfo.name})}) {\n int pageNum = $!{tool.firstLowerCase($!{tableInfo.name})}.getPageNum();\n int pageSize = $!{tool.firstLowerCase($!{tableInfo.name})}.getPageSize();\n Page page = PageHelper.startPage(pageNum, pageSize);\n List<$!{tableInfo.name}VO> result = $!{tool.firstLowerCase($!{tableInfo.name})}Dao.queryAll($!{tool.firstLowerCase($!{tableInfo.name})});\n return ApiResult.success(new PageResult<>(page.getTotal(), result, pageSize, pageNum));\n \n }\n \n /**\n * 新增数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象\n * @return 实例对象\n */\n @Override\n public int insert($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO) {\n $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}) = new $!{tableInfo.name}();\n BeanUtils.copyProperties($!tool.firstLowerCase($!{tableInfo.name})VO,$!tool.firstLowerCase($!{tableInfo.name}));\n return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.insert($!tool.firstLowerCase($!{tableInfo.name}));\n }\n\n /**\n * 修改数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象\n * @return 实例对象\n */\n @Override\n public int update($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO) {\n $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}) = new $!{tableInfo.name}();\n BeanUtils.copyProperties($!tool.firstLowerCase($!{tableInfo.name})VO,$!tool.firstLowerCase($!{tableInfo.name}));\n return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.update($!tool.firstLowerCase($!{tableInfo.name}));\n }\n\n /**\n * 通过主键删除数据\n *\n * @param $!pk.name 主键\n * @return 是否成功\n */\n @Override\n public boolean deleteById($!pk.shortType $!pk.name) {\n return this.$!{tool.firstLowerCase($!{tableInfo.name})}Dao.deleteById($!pk.name) > 0;\n }\n}" + }, { + "name" : "dao.java", + "code" : "##定义初始变量\n#set($tableName = $tool.append($tableInfo.name, \"Dao\"))\n##设置回调\n$!callback.setFileName($tool.append($tableName, \".java\"))\n$!callback.setSavePath($tool.append($tableInfo.savePath, \"/dao\"))\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}dao;\n\nimport $!{tableInfo.savePackageName}.model.$!{tableInfo.name};\nimport $!{tableInfo.savePackageName}.vo.$!{tableInfo.name}VO;\nimport org.apache.ibatis.annotations.Param;\nimport org.apache.ibatis.annotations.Mapper;\nimport java.util.List;\nimport com.baomidou.mybatisplus.core.mapper.BaseMapper;\n\n /**\n* @Title: $!{tableInfo.comment}($!{tableInfo.name})表数据库访问层\n* @Description: \n* @Version:1.0.0 \n* @Since:jdk1.8 \n* @author $author\n* @date $!time.currTime()\n*/\n@Mapper\npublic interface $!{tableName} extends BaseMapper<$!tableInfo.name> {\n\n /**\n * 通过ID查询单条数据\n *\n * @param $!pk.name 主键\n * @return 实例对象\n */\n $!{tableInfo.name}VO queryById($!pk.shortType $!pk.name);\n\n \n /**\n * 通过实体查询一条数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象\n * @return 对象列表\n */\n $!{tableInfo.name}VO findOne($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO);\n\n /**\n * 通过实体作为筛选条件查询\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象\n * @return 对象列表\n */\n List<$!{tableInfo.name}VO> queryAll($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO);\n\n /**\n * 新增数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象\n * @return 影响行数\n */\n int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));\n\n /**\n * 批量新增数据(MyBatis原生foreach方法)\n *\n * @param entities List<$!{tableInfo.name}> 实例对象列表\n * @return 影响行数\n */\n int insertBatch(@Param(\"entities\") List<$!{tableInfo.name}> entities);\n\n /**\n * 批量新增或按主键更新数据(MyBatis原生foreach方法)\n *\n * @param entities List<$!{tableInfo.name}> 实例对象列表\n * @return 影响行数\n */\n int insertOrUpdateBatch(@Param(\"entities\") List<$!{tableInfo.name}> entities);\n\n /**\n * 修改数据\n *\n * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象\n * @return 影响行数\n */\n int update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));\n\n /**\n * 通过主键删除数据\n *\n * @param $!pk.name 主键\n * @return 影响行数\n */\n int deleteById($!pk.shortType $!pk.name);\n\n}\n" + }, { + "name" : "vo.java", + "code" : "##引入宏定义\n$!define\n#set($tableName = $tool.append($tableInfo.name, \"VO\"))\n##设置回调\n$!callback.setFileName($tool.append($tableName, \".java\"))\n$!callback.setSavePath($tool.append($tableInfo.savePath, \"/vo\"))\n\n#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}vo;\n##使用全局变量实现默认包导入\n$!autoImport\nimport java.io.Serializable;\nimport com.alibaba.fastjson.JSONObject;\nimport io.swagger.annotations.ApiModel;\nimport io.swagger.annotations.ApiModelProperty;\nimport lombok.Data;\nimport java.sql.Date;\nimport com.pancm.vo.BasePage;\n\n/**\n* @Title: $!{tableInfo.comment}($!{tableInfo.name})请求响应对象\n* @Description: \n* @Version:1.0.0 \n* @Since:jdk1.8 \n* @author $author\n* @date $!time.currTime()\n*/\n@ApiModel(value = \"$!{tableInfo.name}\", description = \"$!{tableInfo.comment}\")\n@Data\npublic class $!{tableInfo.name}VO extends BasePage implements Serializable {\n private static final long serialVersionUID = $!tool.serial();\n#foreach($column in $tableInfo.fullColumn)\n #if(${column.comment})\n /**\n * ${column.comment}\n */\n #end\n @ApiModelProperty(value = \"${column.comment}\")\n private $!{tool.getClsNameByFullName($column.type)} $!{column.name};\n #end\n\n\n\n @Override\n public String toString(){\n return JSONObject.toJSONString(this);\n }\n\n}" + }, { + "name" : "model.java", + "code" : "\n##导入宏定义\n$!{define.vm}\n\n##保存文件(宏定义)\n#save(\"/model\", \".java\")\n\n##包路径(宏定义)\n#setPackageSuffix(\"model\")\n\n\nimport com.alibaba.fastjson.JSONObject;\nimport lombok.Data;\n\nimport javax.persistence.Column;\nimport javax.persistence.Table;\nimport java.io.Serializable;\nimport java.sql.Date;\n\n /**\n* @Title: $!{tableInfo.comment}($!{tableInfo.name})实体类\n* @Description: \n* @Version:1.0.0 \n* @Since:jdk1.8 \n* @author $author\n* @date $!time.currTime()\n*/\n@Data\n@Table(name = \"$tableInfo.obj.name\")\npublic class $!{tableInfo.name} implements Serializable {\n private static final long serialVersionUID = $!tool.serial();\n#foreach($column in $tableInfo.fullColumn)\n #if(${column.comment})\n /**\n * ${column.comment}\n */\n #end\n @Column(name = \"$column.obj.name\")\n private $!{tool.getClsNameByFullName($column.type)} $!{column.name};\n#end\n\n\n @Override\n public String toString(){\n return JSONObject.toJSONString(this);\n }\n\n}" + }, { + "name" : "mapper.xml.vm", + "code" : "##引入mybatis支持\n$!{mybatisSupport.vm}\n\n##设置保存名称与保存位置\n$!callback.setFileName($tool.append($!{tableInfo.name}, \"Mapper.xml\"))\n$!callback.setSavePath($tool.append($modulePath, \"/src/main/resources/pancm/mapper\"))\n\n##拿到主键\n#if(!$tableInfo.pkColumn.isEmpty())\n #set($pk = $tableInfo.pkColumn.get(0))\n#end\n\n\n\n\n\n \n#foreach($column in $tableInfo.fullColumn)\n \n#end\n \n\n \n \n \n \n \n\n \n \n\n \n \n insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($foreach.hasNext), #end#end)\n values (#foreach($column in $tableInfo.otherColumn)#{$!{column.name}}#if($foreach.hasNext), #end#end)\n \n\n \n insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($foreach.hasNext), #end#end)\n values\n \n (#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($foreach.hasNext), #end#end)\n \n \n\n \n insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($foreach.hasNext), #end#end)\n values\n \n (#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($foreach.hasNext), #end#end)\n \n on duplicate key update\n #foreach($column in $tableInfo.otherColumn)$!column.obj.name = values($!column.obj.name) #if($foreach.hasNext), #end#end\n \n\n \n \n update $!{tableInfo.obj.name}\n \n#foreach($column in $tableInfo.otherColumn)\n \n $!column.obj.name = #{$!column.name},\n \n#end\n \n where $!pk.obj.name = #{$!pk.name}\n \n\n \n \n delete from $!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name}\n \n\n\n" + } ] } }, "columnConfig" : { diff --git a/springboot-demo/pom.xml b/springboot-demo/pom.xml index 89e9d92..8f066f6 100644 --- a/springboot-demo/pom.xml +++ b/springboot-demo/pom.xml @@ -108,6 +108,11 @@ mapper-spring-boot-starter ${tk.mybatis.boot.version} + + com.baomidou + mybatis-plus-boot-starter + 3.0.5 + org.mybatis.generator diff --git a/springboot-demo/src/main/java/com/pancm/controller/TSysUserController.java b/springboot-demo/src/main/java/com/pancm/controller/TSysUserController.java new file mode 100644 index 0000000..8483569 --- /dev/null +++ b/springboot-demo/src/main/java/com/pancm/controller/TSysUserController.java @@ -0,0 +1,103 @@ +package com.pancm.controller; + +import com.pancm.vo.TSysUserVO; +import com.pancm.service.ITSysUserService; +import org.springframework.web.bind.annotation.*; + + +import com.pancm.vo.ApiResult; +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: 用户表(TSysUser)表控制层 +* @Description: +* @Version:1.0.0 +* @Since:jdk1.8 +* @author pancm +* @date 2024-04-01 09:30:51 +*/ +@Api(tags = "用户表(TSysUser)") +@RestController +@RequestMapping("tSysUser") +public class TSysUserController { + /** + * 服务对象 + */ + @Autowired + private ITSysUserService tSysUserService; + + + /** + * 新增一条数据 + * + * @param tSysUserVO 实体类 + * @return Response对象 + */ + @ApiOperation(value = "用户表新增",notes = "用户表新增") + @RequestMapping(value = "save", method = RequestMethod.POST) + public ApiResult insert(@RequestBody TSysUserVO tSysUserVO, HttpServletRequest httpRequest) { + int result = tSysUserService.insert(tSysUserVO); + if (result > 0) { + return ApiResult.success(); + } + return ApiResult.error("新增失败"); + } + + /** + * 修改一条数据 + * + * @param tSysUserVO 实体类 + * @return Response对象 + */ + @ApiOperation(value = "用户表修改",notes = "用户表修改") + @RequestMapping(value = "edit", method = RequestMethod.POST) + public ApiResult update(@RequestBody TSysUserVO tSysUserVO, HttpServletRequest httpRequest) { + tSysUserService.update(tSysUserVO); + return ApiResult.success(); + } + + /** + * 删除一条数据 + * + * @param tSysUserVO 参数对象 + * @return Response对象 + */ + @ApiOperation(value = "用户表删除",notes = "用户表删除") + @RequestMapping(value = "del", method = RequestMethod.POST) + public ApiResult delete(@RequestBody TSysUserVO tSysUserVO, HttpServletRequest httpRequest) { + tSysUserService.deleteById(tSysUserVO.getId()); + return ApiResult.success(); + } + + + + /** + * 分页查询 + * + */ + @ApiOperation(value = "用户表查询",notes = "用户表查询") + @RequestMapping(value = "list", method = RequestMethod.POST) + public ApiResult list(@RequestBody TSysUserVO tSysUserVO) { + return tSysUserService.list(tSysUserVO); + } + + /** + * 详情查询 + * + */ + @ApiOperation(value = "用户表详情",notes = "用户表详情") + @RequestMapping(value = "view", method = RequestMethod.GET) + public ApiResult view( @RequestParam("id") String id) { + return ApiResult.success(tSysUserService.queryById(id)); + } +} diff --git a/springboot-demo/src/main/java/com/pancm/dao/TSysUserDao.java b/springboot-demo/src/main/java/com/pancm/dao/TSysUserDao.java new file mode 100644 index 0000000..c067c6f --- /dev/null +++ b/springboot-demo/src/main/java/com/pancm/dao/TSysUserDao.java @@ -0,0 +1,87 @@ +package com.pancm.dao; + +import com.pancm.model.TSysUser; +import com.pancm.vo.TSysUserVO; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Mapper; +import java.util.List; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + + /** +* @Title: 用户表(TSysUser)表数据库访问层 +* @Description: +* @Version:1.0.0 +* @Since:jdk1.8 +* @author pancm +* @date 2024-04-01 09:30:54 +*/ +@Mapper +public interface TSysUserDao extends BaseMapper { + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + TSysUserVO queryById(String id); + + + /** + * 通过实体查询一条数据 + * + * @param tSysUserVO 实例对象 + * @return 对象列表 + */ + TSysUserVO findOne(TSysUserVO tSysUserVO); + + /** + * 通过实体作为筛选条件查询 + * + * @param tSysUserVO 实例对象 + * @return 对象列表 + */ + List queryAll(TSysUserVO tSysUserVO); + + /** + * 新增数据 + * + * @param tSysUser 实例对象 + * @return 影响行数 + */ + int insert(TSysUser tSysUser); + + /** + * 批量新增数据(MyBatis原生foreach方法) + * + * @param entities List 实例对象列表 + * @return 影响行数 + */ + int insertBatch(@Param("entities") List entities); + + /** + * 批量新增或按主键更新数据(MyBatis原生foreach方法) + * + * @param entities List 实例对象列表 + * @return 影响行数 + */ + int insertOrUpdateBatch(@Param("entities") List entities); + + /** + * 修改数据 + * + * @param tSysUser 实例对象 + * @return 影响行数 + */ + int update(TSysUser tSysUser); + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 影响行数 + */ + int deleteById(String id); + +} + diff --git a/springboot-demo/src/main/java/com/pancm/dao/UserDao.java b/springboot-demo/src/main/java/com/pancm/dao/UserDao.java index bce150e..4992e68 100644 --- a/springboot-demo/src/main/java/com/pancm/dao/UserDao.java +++ b/springboot-demo/src/main/java/com/pancm/dao/UserDao.java @@ -4,6 +4,8 @@ import com.pancm.vo.UserVO; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Mapper; +import tk.mybatis.mapper.common.BaseMapper; + import java.util.List; /** @@ -15,7 +17,7 @@ * @date 2024-01-15 15:27:04 */ @Mapper -public interface UserDao { +public interface UserDao { /** * 通过ID查询单条数据 diff --git a/springboot-demo/src/main/java/com/pancm/model/TSysUser.java b/springboot-demo/src/main/java/com/pancm/model/TSysUser.java new file mode 100644 index 0000000..5ded285 --- /dev/null +++ b/springboot-demo/src/main/java/com/pancm/model/TSysUser.java @@ -0,0 +1,61 @@ +package com.pancm.model; + + +import com.alibaba.fastjson.JSONObject; +import lombok.Data; + +import javax.persistence.Column; +import javax.persistence.Table; +import java.io.Serializable; +import java.sql.Date; + + /** +* @Title: 用户表(TSysUser)实体类 +* @Description: +* @Version:1.0.0 +* @Since:jdk1.8 +* @author pancm +* @date 2024-04-01 09:30:55 +*/ +@Data +@Table(name = "t_sys_user") +public class TSysUser implements Serializable { + private static final long serialVersionUID = -56958960669065369L; + /** + * 主键 + */ + @Column(name = "id") + private String id; + /** + * 用户账号 + */ + @Column(name = "username") + private String username; + /** + * 用户密码 + */ + @Column(name = "password") + private String password; + /** + * 昵称 + */ + @Column(name = "nickname") + private String nickname; + /** + * 部门id + */ + @Column(name = "dep_id") + private Integer depId; + /** + * 岗位id + */ + @Column(name = "pos_id") + private String posId; + + + @Override + public String toString(){ + return JSONObject.toJSONString(this); + } + +} diff --git a/springboot-demo/src/main/java/com/pancm/service/ITSysUserService.java b/springboot-demo/src/main/java/com/pancm/service/ITSysUserService.java new file mode 100644 index 0000000..77d97b4 --- /dev/null +++ b/springboot-demo/src/main/java/com/pancm/service/ITSysUserService.java @@ -0,0 +1,62 @@ +package com.pancm.service; + +import com.pancm.vo.TSysUserVO; +import com.pancm.model.TSysUser; +import com.pancm.vo.ApiResult; +import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; + + + /** +* @Title: 用户表(TSysUser)表服务接口 +* @Description: +* @Version:1.0.0 +* @Since:jdk1.8 +* @author pancm +* @date 2024-04-01 09:30:53 +*/ +public interface ITSysUserService extends IService{ + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + TSysUserVO queryById(String id); + + + /** + * 通过实体作为筛选条件查询 + * + * @param tSysUserVO 实例对象 + * @return 对象列表 + */ + ApiResult list(TSysUserVO tSysUserVO); + + + /** + * 新增数据 + * + * @param tSysUserVO 实例对象 + * @return 实例对象 + */ + int insert(TSysUserVO tSysUserVO); + + /** + * 修改数据 + * + * @param tSysUserVO 实例对象 + * @return 实例对象 + */ + int update(TSysUserVO tSysUserVO); + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 是否成功 + */ + boolean deleteById(String id); + +} diff --git a/springboot-demo/src/main/java/com/pancm/service/impl/TSysUserServiceImpl.java b/springboot-demo/src/main/java/com/pancm/service/impl/TSysUserServiceImpl.java new file mode 100644 index 0000000..da98bb8 --- /dev/null +++ b/springboot-demo/src/main/java/com/pancm/service/impl/TSysUserServiceImpl.java @@ -0,0 +1,97 @@ +package com.pancm.service.impl; + + +import com.pancm.vo.TSysUserVO; +import com.pancm.model.TSysUser; +import com.pancm.dao.TSysUserDao; +import com.pancm.service.ITSysUserService; + +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; +import com.pancm.vo.ApiResult; +import com.pancm.vo.PageResult; +import org.springframework.stereotype.Service; +import org.springframework.beans.BeanUtils; +import javax.annotation.Resource; +import java.util.List; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + + + +/** +* @Title: 用户表(TSysUser)表服务实现类 +* @Description: +* @Version:1.0.0 +* @Since:jdk1.8 +* @author pancm +* @date 2024-04-01 09:30:54 +*/ +@Service("tSysUserService") +public class TSysUserServiceImpl extends ServiceImpl implements ITSysUserService { + @Resource + private TSysUserDao tSysUserDao; + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + @Override + public TSysUserVO queryById(String id) { + return this.tSysUserDao.queryById(id); + } + + + /** + * 根据条件查询 + * + * @return 实例对象的集合 + */ + @Override + public ApiResult list(TSysUserVO tSysUser) { + int pageNum = tSysUser.getPageNum(); + int pageSize = tSysUser.getPageSize(); + Page page = PageHelper.startPage(pageNum, pageSize); + List result = tSysUserDao.queryAll(tSysUser); + return ApiResult.success(new PageResult<>(page.getTotal(), result, pageSize, pageNum)); + + } + + /** + * 新增数据 + * + * @param tSysUserVO 实例对象 + * @return 实例对象 + */ + @Override + public int insert(TSysUserVO tSysUserVO) { + TSysUser tSysUser = new TSysUser(); + BeanUtils.copyProperties(tSysUserVO,tSysUser); + return tSysUserDao.insert(tSysUser); + } + + /** + * 修改数据 + * + * @param tSysUserVO 实例对象 + * @return 实例对象 + */ + @Override + public int update(TSysUserVO tSysUserVO) { + TSysUser tSysUser = new TSysUser(); + BeanUtils.copyProperties(tSysUserVO,tSysUser); + return tSysUserDao.update(tSysUser); + } + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 是否成功 + */ + @Override + public boolean deleteById(String id) { + return this.tSysUserDao.deleteById(id) > 0; + } +} diff --git a/springboot-demo/src/main/java/com/pancm/vo/TSysUserVO.java b/springboot-demo/src/main/java/com/pancm/vo/TSysUserVO.java new file mode 100644 index 0000000..5bcfc34 --- /dev/null +++ b/springboot-demo/src/main/java/com/pancm/vo/TSysUserVO.java @@ -0,0 +1,61 @@ +package com.pancm.vo; + +import java.io.Serializable; +import com.alibaba.fastjson.JSONObject; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import java.sql.Date; +import com.pancm.vo.BasePage; + +/** +* @Title: 用户表(TSysUser)请求响应对象 +* @Description: +* @Version:1.0.0 +* @Since:jdk1.8 +* @author pancm +* @date 2024-04-01 09:30:54 +*/ +@ApiModel(value = "TSysUser", description = "用户表") +@Data +public class TSysUserVO extends BasePage implements Serializable { + private static final long serialVersionUID = 855666123415935768L; + /** + * 主键 + */ + @ApiModelProperty(value = "主键") + private String id; + /** + * 用户账号 + */ + @ApiModelProperty(value = "用户账号") + private String username; + /** + * 用户密码 + */ + @ApiModelProperty(value = "用户密码") + private String password; + /** + * 昵称 + */ + @ApiModelProperty(value = "昵称") + private String nickname; + /** + * 部门id + */ + @ApiModelProperty(value = "部门id") + private Integer depId; + /** + * 岗位id + */ + @ApiModelProperty(value = "岗位id") + private String posId; + + + + @Override + public String toString(){ + return JSONObject.toJSONString(this); + } + +} diff --git a/springboot-demo/src/main/resources/pancm/mapper/TSysUserMapper.xml b/springboot-demo/src/main/resources/pancm/mapper/TSysUserMapper.xml new file mode 100644 index 0000000..5682b64 --- /dev/null +++ b/springboot-demo/src/main/resources/pancm/mapper/TSysUserMapper.xml @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + insert into t_sys_user(username, password, nickname, dep_id, pos_id) + values (#{username}, #{password}, #{nickname}, #{depId}, #{posId}) + + + + insert into t_sys_user(username, password, nickname, dep_id, pos_id) + values + + (#{entity.username}, #{entity.password}, #{entity.nickname}, #{entity.depId}, #{entity.posId}) + + + + + insert into t_sys_user(username, password, nickname, dep_id, pos_id) + values + + (#{entity.username}, #{entity.password}, #{entity.nickname}, #{entity.depId}, #{entity.posId}) + + on duplicate key update +username = values(username) , password = values(password) , nickname = values(nickname) , dep_id = values(dep_id) , pos_id = values(pos_id) + + + + update t_sys_user + + + username = #{username}, + + + password = #{password}, + + + nickname = #{nickname}, + + + dep_id = #{depId}, + + + pos_id = #{posId}, + + + where id = #{id} + + + + + delete from t_sys_user where id = #{id} + + + +