1. ##定义初始变量
  2. #set($tableName = $tool.append($tableInfo.name, "Controller"))
  3. ##设置回调
  4. $!callback.setFileName($tool.append($tableName, ".java"))
  5. $!callback.setSavePath($tool.append($tableInfo.savePath, "/controller"))
  6. ##拿到主键
  7. #if(!$tableInfo.pkColumn.isEmpty())
  8. #set($pk = $tableInfo.pkColumn.get(0))
  9. #end
  10.  
  11. #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller;
  12.  
  13. import com.ruoyi.common.core.web.page.TableDataInfo;
  14. import $!{tableInfo.savePackageName}.domain.$!{tableInfo.name};
  15. import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
  16. import org.springframework.web.bind.annotation.*;
  17. import com.ruoyi.common.core.web.domain.AjaxResult;
  18. import com.ruoyi.common.core.web.controller.BaseController;
  19. import java.util.List;
  20.  
  21. import javax.annotation.Resource;
  22.  
  23. /**
  24. * $!{tableInfo.comment}($!{tableInfo.name})表控制层
  25. *
  26. * @author $!author
  27. * @since $!time.currTime()
  28. */
  29. @RestController
  30. @RequestMapping("$!tool.firstLowerCase($tableInfo.name)")
  31. public class $!{tableName} extends BaseController {
  32. /**
  33. * 服务对象
  34. */
  35. @Resource
  36. private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;
  37.  
  38. /**
  39. * 分页查询
  40. *
  41. * @param $!{tool.firstLowerCase($tableInfo.name)} 筛选条件
  42. * @return 查询结果
  43. */
  44. @GetMapping("list")
  45. public TableDataInfo<$!{tableInfo.name}> listPage($!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
  46. startPage();
  47. List<$!{tableInfo.name}> list = this.$!{tool.firstLowerCase($tableInfo.name)}Service.list($!{tool.firstLowerCase($tableInfo.name)});
  48. return getDataTable(list);
  49. }
  50.  
  51. /**
  52. * 通过主键查询单条数据
  53. *
  54. * @param id 主键
  55. * @return 单条数据
  56. */
  57. @GetMapping("{id}")
  58. public AjaxResult<$!{tableInfo.name}> query(@PathVariable("id") $!pk.shortType id) {
  59. return AjaxResult.success(this.$!{tool.firstLowerCase($tableInfo.name)}Service.getById(id));
  60. }
  61.  
  62. /**
  63. * 新增数据
  64. *
  65. * @param $!{tool.firstLowerCase($tableInfo.name)} 实体
  66. * @return 新增结果
  67. */
  68. @PostMapping
  69. public AjaxResult add($!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
  70. return this.$!{tool.firstLowerCase($tableInfo.name)}Service.insert($!{tool.firstLowerCase($tableInfo.name)}) ? AjaxResult.success() : AjaxResult.error400();
  71. }
  72.  
  73. /**
  74. * 编辑数据
  75. *
  76. * @param $!{tool.firstLowerCase($tableInfo.name)} 实体
  77. * @return 编辑结果
  78. */
  79. @PutMapping
  80. public AjaxResult edit($!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
  81. return this.$!{tool.firstLowerCase($tableInfo.name)}Service.update($!{tool.firstLowerCase($tableInfo.name)}) ? AjaxResult.success() : AjaxResult.error400();
  82. }
  83.  
  84. /**
  85. * 删除数据
  86. *
  87. * @param id 主键
  88. * @return 删除是否成功
  89. */
  90. @DeleteMapping
  91. public AjaxResult deleteById($!pk.shortType id) {
  92. return this.$!{tool.firstLowerCase($tableInfo.name)}Service.deleteById(id) ? AjaxResult.success() : AjaxResult.error400();
  93. }
  94.  
  95. }
  1. ##定义初始变量
  2. #set($tableName = $tool.append($tableInfo.name, "Mapper"))
  3. ##设置回调
  4. $!callback.setFileName($tool.append($tableName, ".java"))
  5. $!callback.setSavePath($tool.append($tableInfo.savePath, "/mapper"))
  6.  
  7. ##拿到主键
  8. #if(!$tableInfo.pkColumn.isEmpty())
  9. #set($pk = $tableInfo.pkColumn.get(0))
  10. #end
  11.  
  12. #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}mapper;
  13.  
  14. import $!{tableInfo.savePackageName}.domain.$!{tableInfo.name};
  15. import org.apache.ibatis.annotations.Param;
  16. import java.util.List;
  17.  
  18. /**
  19. * $!{tableInfo.comment}($!{tableInfo.name})表数据库访问层
  20. *
  21. * @author $!author
  22. * @since $!time.currTime()
  23. */
  24. public interface $!{tableName} {
  25.  
  26. /**
  27. * 通过ID查询单条数据
  28. *
  29. * @param $!pk.name 主键
  30. * @return 实例对象
  31. */
  32. $!{tableInfo.name} getById($!pk.shortType $!pk.name);
  33.  
  34. /**
  35. * 查询指定行数据
  36. *
  37. * @param $!tool.firstLowerCase($!{tableInfo.name}) 查询条件
  38. * @return 对象列表
  39. */
  40. List<$!{tableInfo.name}> list($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
  41.  
  42. /**
  43. * 统计总行数
  44. *
  45. * @param $!tool.firstLowerCase($!{tableInfo.name}) 查询条件
  46. * @return 总行数
  47. */
  48. long count($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
  49.  
  50. /**
  51. * 新增数据
  52. *
  53. * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
  54. * @return 影响行数
  55. */
  56. int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
  57.  
  58. /**
  59. * 批量新增数据(MyBatis原生foreach方法)
  60. *
  61. * @param entities List<$!{tableInfo.name}> 实例对象列表
  62. * @return 影响行数
  63. */
  64. int insertBatch(@Param("entities") List<$!{tableInfo.name}> entities);
  65.  
  66. /**
  67. * 批量新增或按主键更新数据(MyBatis原生foreach方法)
  68. *
  69. * @param entities List<$!{tableInfo.name}> 实例对象列表
  70. * @return 影响行数
  71. * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参
  72. */
  73. int insertOrUpdateBatch(@Param("entities") List<$!{tableInfo.name}> entities);
  74.  
  75. /**
  76. * 修改数据
  77. *
  78. * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
  79. * @return 影响行数
  80. */
  81. int update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
  82.  
  83. /**
  84. * 通过主键删除数据
  85. *
  86. * @param $!pk.name 主键
  87. * @return 影响行数
  88. */
  89. int deleteById($!pk.shortType $!pk.name);
  90.  
  91. }
  1. ##引入宏定义
  2. $!{define.vm}
  3.  
  4. ##使用宏定义设置回调(保存位置与文件后缀)
  5. #save("/domain", ".java")
  6.  
  7. ##使用宏定义设置包后缀
  8. #setPackageSuffix("domain")
  9.  
  10. ##使用全局变量实现默认包导入
  11. $!{autoImport.vm}
  12. import java.io.Serializable;
  13.  
  14. ##使用宏定义实现类注释信息
  15. #tableComment("实体类")
  16. public class $!{tableInfo.name} implements Serializable {
  17. private static final long serialVersionUID = $!tool.serial();
  18. #foreach($column in $tableInfo.fullColumn)
  19. #if(${column.comment})/**
  20. * ${column.comment}
  21. */#end
  22.  
  23. private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
  24. #end
  25.  
  26. #foreach($column in $tableInfo.fullColumn)
  27. ##使用宏定义实现get,set方法
  28. #getSetMethod($column)
  29. #end
  30.  
  31. }

##引入mybatis支持
$!{mybatisSupport.vm}

##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "Mapper.xml"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/mapper"))

##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="$!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper">

<resultMap id="$!{tableInfo.name}Po" type="$!{tableInfo.savePackageName}.domain.$!{tableInfo.name}">
<!--@Table $!{tableInfo.obj.name}-->
#foreach($column in $tableInfo.fullColumn)
<result property="$!column.name" column="$!column.obj.name" jdbcType="$!column.ext.jdbcType"/>
#end
</resultMap>

<sql id="selectPo">
select
#allSqlColumn()

from $!tableInfo.obj.name
</sql>

<!--查询单个-->
<select id="getById" resultMap="$!{tableInfo.name}Po">
<include refid="selectPo"/>
where $!pk.obj.name = #{$!pk.name}
</select>

<!--查询指定行数据-->
<select id="list" resultMap="$!{tableInfo.name}Po">
<include refid="selectPo"/>
<where>
#foreach($column in $tableInfo.fullColumn)
<if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
and $!column.obj.name = #{$!column.name}
</if>
#end
</where>
order by $!pk.obj.name desc
</select>

<!-- 新增选择列 -->
<insert id="insert" keyProperty="$!pk.name" useGeneratedKeys="true">
insert into $!{tableInfo.obj.name}
<trim prefix="(" suffix=")" suffixOverrides="," >
#foreach($column in $tableInfo.fullColumn)
<if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">`$!column.obj.name`,</if>
#end
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
#foreach($column in $tableInfo.fullColumn)
<if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">#{$!column.name},</if>
#end
</trim>
</insert>

<insert id="insertBatch" keyProperty="$!pk.name" useGeneratedKeys="true">
insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)
values
<foreach collection="entities" item="entity" separator=",">
(#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($velocityHasNext), #end#end)
</foreach>
</insert>

<insert id="insertOrUpdateBatch" keyProperty="$!pk.name" useGeneratedKeys="true">
insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)
values
<foreach collection="entities" item="entity" separator=",">
(#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($velocityHasNext), #end#end)
</foreach>
on duplicate key update
#foreach($column in $tableInfo.otherColumn)$!column.obj.name = values($!column.obj.name)#if($velocityHasNext),
#end#end

</insert>

<!--通过主键修改数据-->
<update id="update">
update $!{tableInfo.obj.name}
<set>
#foreach($column in $tableInfo.otherColumn)
<if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">$!column.obj.name = #{$!column.name},</if>
#end
</set>
where $!pk.obj.name = #{$!pk.name}
</update>

<!--通过主键删除-->
<delete id="deleteById">
delete from $!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name}
</delete>

</mapper>

  1. ##定义初始变量
  2. #set($tableName = $tool.append($tableInfo.name, "Service"))
  3. ##设置回调
  4. $!callback.setFileName($tool.append($tableName, ".java"))
  5. $!callback.setSavePath($tool.append($tableInfo.savePath, "/service"))
  6.  
  7. ##拿到主键
  8. #if(!$tableInfo.pkColumn.isEmpty())
  9. #set($pk = $tableInfo.pkColumn.get(0))
  10. #end
  11.  
  12. #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service;
  13.  
  14. import $!{tableInfo.savePackageName}.domain.$!{tableInfo.name};
  15. import java.util.List;
  16.  
  17. /**
  18. * $!{tableInfo.comment}($!{tableInfo.name})表服务接口
  19. *
  20. * @author $!author
  21. * @since $!time.currTime()
  22. */
  23. public interface $!{tableName} {
  24.  
  25. /**
  26. * 通过ID查询单条数据
  27. *
  28. * @param $!pk.name 主键
  29. * @return 实例对象
  30. */
  31. $!{tableInfo.name} getById($!pk.shortType $!pk.name);
  32.  
  33. /**
  34. * 分页查询
  35. *
  36. * @param $!tool.firstLowerCase($!{tableInfo.name}) 筛选条件
  37. * @return 查询结果
  38. */
  39. List<$!{tableInfo.name}> list($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
  40.  
  41. /**
  42. * 新增数据
  43. *
  44. * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
  45. * @return 实例对象
  46. */
  47. boolean insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
  48.  
  49. /**
  50. * 修改数据
  51. *
  52. * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
  53. * @return 实例对象
  54. */
  55. boolean update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
  56.  
  57. /**
  58. * 通过主键删除数据
  59. *
  60. * @param $!pk.name 主键
  61. * @return 是否成功
  62. */
  63. boolean deleteById($!pk.shortType $!pk.name);
  64.  
  65. }
  1. ##定义初始变量
  2. #set($tableName = $tool.append($tableInfo.name, "ServiceImpl"))
  3. ##设置回调
  4. $!callback.setFileName($tool.append($tableName, ".java"))
  5. $!callback.setSavePath($tool.append($tableInfo.savePath, "/service/impl"))
  6.  
  7. ##拿到主键
  8. #if(!$tableInfo.pkColumn.isEmpty())
  9. #set($pk = $tableInfo.pkColumn.get(0))
  10. #end
  11.  
  12. #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service.impl;
  13.  
  14. import $!{tableInfo.savePackageName}.domain.$!{tableInfo.name};
  15. import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper;
  16. import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
  17. import org.springframework.stereotype.Service;
  18. import java.util.List;
  19.  
  20. import javax.annotation.Resource;
  21.  
  22. /**
  23. * $!{tableInfo.comment}($!{tableInfo.name})表服务实现类
  24. *
  25. * @author $!author
  26. * @since $!time.currTime()
  27. */
  28. @Service("$!tool.firstLowerCase($!{tableInfo.name})Service")
  29. public class $!{tableName} implements $!{tableInfo.name}Service {
  30. @Resource
  31. private $!{tableInfo.name}Mapper $!tool.firstLowerCase($!{tableInfo.name})Mapper;
  32.  
  33. /**
  34. * 通过ID查询单条数据
  35. *
  36. * @param $!pk.name 主键
  37. * @return 实例对象
  38. */
  39. @Override
  40. public $!{tableInfo.name} getById($!pk.shortType $!pk.name) {
  41. return this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.getById($!pk.name);
  42. }
  43.  
  44. /**
  45. * 分页查询
  46. *
  47. * @param $!{tool.firstLowerCase($tableInfo.name)} 筛选条件
  48. * @return 查询结果
  49. */
  50. @Override
  51. public List<$!{tableInfo.name}> list($!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
  52. return this.$!{tool.firstLowerCase($tableInfo.name)}Mapper.list($!{tool.firstLowerCase($tableInfo.name)});
  53. }
  54.  
  55. /**
  56. * 新增数据
  57. *
  58. * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
  59. * @return 实例对象
  60. */
  61. @Override
  62. public boolean insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
  63. return this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.insert($!tool.firstLowerCase($!{tableInfo.name})) > 0;
  64. }
  65.  
  66. /**
  67. * 修改数据
  68. *
  69. * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
  70. * @return 实例对象
  71. */
  72. @Override
  73. public boolean update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
  74. return this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.update($!tool.firstLowerCase($!{tableInfo.name})) > 0;
  75. }
  76.  
  77. /**
  78. * 通过主键删除数据
  79. *
  80. * @param $!pk.name 主键
  81. * @return 是否成功
  82. */
  83. @Override
  84. public boolean deleteById($!pk.shortType $!pk.name) {
  85. return this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.deleteById($!pk.name) > 0;
  86. }
  87. }

easycode模版-基于ruoyi-cloud的更多相关文章

  1. 基于Spring Cloud和Netflix OSS 构建微服务-Part 1

    前一篇文章<微服务操作模型>中,我们定义了微服务使用的操作模型.这篇文章中,我们将开始使用Spring Cloud和Netflix OSS实现这一模型,包含核心部分:服务发现(Servic ...

  2. 基于Spring Cloud和Netflix OSS构建微服务,Part 2

    在上一篇文章中,我们已使用Spring Cloud和Netflix OSS中的核心组件,如Eureka.Ribbon和Zuul,部分实现了操作模型(operations model),允许单独部署的微 ...

  3. 基于Spring Cloud、JWT 的微服务权限系统设计

    基于Spring Cloud.JWT 的微服务权限系统设计 https://gitee.com/log4j/pig https://github.com/kioyong/spring-cloud-de ...

  4. 基于Spring cloud Ribbon和Eureka实现客户端负载均衡

    前言 本案例将基于Spring cloud Ribbon和Eureka实现客户端负载均衡,其中Ribbon用于实现客户端负载均衡,Eureka主要是用于服务注册及发现: 传统的服务端负载均衡 常见的服 ...

  5. 基于Spring Cloud的微服务入门教程

    (本教程的原地址发布在本人的简书上:http://www.jianshu.com/p/947d57d042e7,若各位看官有什么问题或不同看法请在这里或简书留言,谢谢!) 本人也是前段时间才开始接触S ...

  6. 干货|基于 Spring Cloud 的微服务落地

    转自 微服务架构模式的核心在于如何识别服务的边界,设计出合理的微服务.但如果要将微服务架构运用到生产项目上,并且能够发挥该架构模式的重要作用,则需要微服务框架的支持. 在Java生态圈,目前使用较多的 ...

  7. 基于Spring Cloud的微服务落地

    微服务架构模式的核心在于如何识别服务的边界,设计出合理的微服务.但如果要将微服务架构运用到生产项目上,并且能够发挥该架构模式的重要作用,则需要微服务框架的支持. 在Java生态圈,目前使用较多的微服务 ...

  8. Weshop基于Spring Cloud开发的小程序商城系统

    WESHOP | 基于微服务的小程序商城系统 Weshop是基于Spring Cloud(Greenwich)开发的小程序商城系统,提供整套公共微服务服务模块,包含用户中心.商品中心.订单中心.营销中 ...

  9. 基于Spring Cloud 几行配置完成单点登录开发

    单点登录概念 单点登录(Single Sign On),简称为 SSO,是目前比较流行的企业业务整合的解决方案之一.SSO的定义是在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统. ...

  10. 基于 Spring Cloud 的微服务架构实践指南(下)

    show me the code and talk to me,做的出来更要说的明白 本文源码,请点击learnSpringCloud 我是布尔bl,你的支持是我分享的动力! 一.引入 上回 基于 S ...

随机推荐

  1. Finance财务软件(权限管理专题)

    我们支持按模块对用户授权 如上所示,我们对用户test进行授权.test登录系统后将看不到未授权的菜单:

  2. C++时间日期相关

    // 计时 #pragma once #include <iostream> #include <thread> #include <chrono> #includ ...

  3. visual studio 2015 IOS开发连接mac时提示错误couldn't connect to xxxx, please try again的一个方法

    本人使用虚拟机MAC.原本使用虚拟机中的VS2015连接正常没有问题. 但是当把MAC的虚拟机文件COPY到另一个机器上,提示"couldn't connect to xxxx,  plea ...

  4. go读取excel的内容

    import "github.com/360EntSecGroup-Skylar/excelize" func SimulationDataHandler(){ f, err := ...

  5. windows 批量杀进程

    1 import psutil 2 from subprocess import Popen, PIPE 3 4 process_name ="bsmr.exe,fxclient.exe,F ...

  6. 根据STM32CubeMX软件创建STM32芯片的Altium Designer原理图库教程-转载

    (24条消息) 根据STM32CubeMX软件创建STM32芯片的Altium Designer原理图库教程_奥比克_阿彦少爷的博客-CSDN博客_stm32原理图库 1所需软件及环境1.STM32C ...

  7. vue中key

    使用key维护列表的状态 当列表的数据变化时,默认情况下,vue尽可能的服用已存在的DOM元素,从而提升渲染的性能.但这种默认的性能优化策略,会导致由状态的列表无法被正确更新. key的使用注意事项: ...

  8. Python打包时包含静态文件处理方法

    Python打包时包含静态文件处理方法 使用场景 已搭建了PyPI私有库,上传公共库包含静态文件,如需要使用sql静态文件初始化数据库. 打包python包,给其他人使用,但项目中包含静态文件,如ht ...

  9. java 类对象四种方法加载方式

    public static void main(String[] args) throws Exception { //第一种 //这里需要做异常处理,或的加载类的类对象类. Class<?&g ...

  10. idea常用快捷键记录

    实用编写代码辅助快捷键 Ctrl+Alt+V 提出选中内容为局部变量 Ctrl+Backspace 按单词删除 Ctrl+D 复制行 Ctrl+Y 删除当前行 Ctr+Shift+U 大小写转化 Sh ...