通用优化

This commit is contained in:
zhujunjieit 2018-12-07 22:23:03 +08:00
parent 96aa2727fe
commit 1353b040a8
35 changed files with 145 additions and 227 deletions

View File

@ -51,6 +51,12 @@
<artifactId>ruoyi-exam</artifactId> <artifactId>ruoyi-exam</artifactId>
<version>${ruoyi.version}</version> <version>${ruoyi.version}</version>
</dependency> </dependency>
<!-- 测试生成的代码-->
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-test</artifactId>
<version>${ruoyi.version}</version>
</dependency>
<!-- 定时任务 <!-- 定时任务
<dependency> <dependency>
<groupId>com.ruoyi</groupId> <groupId>com.ruoyi</groupId>

View File

@ -127,7 +127,7 @@ gen:
# 作者 # 作者
author: zhujj author: zhujj
# 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool # 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool
packageName: com.ruoyi.exam packageName: com.ruoyi.test
# 自动去除表前缀默认是true # 自动去除表前缀默认是true
autoRemovePre: false autoRemovePre: false
# 表前缀(类名不会包含表前缀) # 表前缀(类名不会包含表前缀)

View File

@ -2,7 +2,8 @@ package com.ruoyi.exam.domain;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.base.BaseEntity;
import javax.persistence.Id;
import java.util.Date; import java.util.Date;
/** /**
@ -16,6 +17,7 @@ public class ExamQuestion
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** */ /** */
@Id
private String id; private String id;
/** 问题标题 */ /** 问题标题 */
private String title; private String title;

View File

@ -2,7 +2,8 @@ package com.ruoyi.exam.domain;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.base.BaseEntity;
import javax.persistence.Id;
import java.util.Date; import java.util.Date;
/** /**
@ -16,6 +17,7 @@ public class ExamQuestionCategory
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** */ /** */
@Id
private String id; private String id;
/** 分类 */ /** 分类 */
private String name; private String name;

View File

@ -2,7 +2,8 @@ package com.ruoyi.exam.domain;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.base.BaseEntity;
import javax.persistence.Id;
import java.util.Date; import java.util.Date;
/** /**
@ -16,6 +17,7 @@ public class ExamQuestionComment
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** */ /** */
@Id
private String id; private String id;
/** 点评内容 */ /** 点评内容 */
private Integer content; private Integer content;

View File

@ -2,7 +2,8 @@ package com.ruoyi.exam.domain;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.base.BaseEntity;
import javax.persistence.Id;
import java.util.Date; import java.util.Date;
/** /**
@ -16,6 +17,7 @@ public class ExamQuestionItem
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** */ /** */
@Id
private String id; private String id;
/** 选项内容 */ /** 选项内容 */
private String content; private String content;

View File

@ -5,6 +5,8 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.base.BaseEntity; import com.ruoyi.common.base.BaseEntity;
import javax.persistence.Id;
/** /**
* 参数配置表 sys_config * 参数配置表 sys_config
* *
@ -16,6 +18,7 @@ public class SysConfig extends BaseEntity
/** 参数主键 */ /** 参数主键 */
@Excel(name = "参数主键") @Excel(name = "参数主键")
@Id
private Long configId; private Long configId;
/** 参数名称 */ /** 参数名称 */

View File

@ -4,6 +4,8 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.base.BaseEntity; import com.ruoyi.common.base.BaseEntity;
import javax.persistence.Id;
/** /**
* 部门表 sys_dept * 部门表 sys_dept
* *
@ -14,6 +16,7 @@ public class SysDept extends BaseEntity
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 部门ID */ /** 部门ID */
@Id
private Long deptId; private Long deptId;
/** 父部门ID */ /** 父部门ID */

View File

@ -5,6 +5,8 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.base.BaseEntity; import com.ruoyi.common.base.BaseEntity;
import javax.persistence.Id;
/** /**
* 字典数据表 sys_dict_data * 字典数据表 sys_dict_data
* *
@ -16,6 +18,7 @@ public class SysDictData extends BaseEntity
/** 字典编码 */ /** 字典编码 */
@Excel(name = "字典编码") @Excel(name = "字典编码")
@Id
private Long dictCode; private Long dictCode;
/** 字典排序 */ /** 字典排序 */

View File

@ -5,6 +5,8 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.base.BaseEntity; import com.ruoyi.common.base.BaseEntity;
import javax.persistence.Id;
/** /**
* 字典类型表 sys_dict_type * 字典类型表 sys_dict_type
* *
@ -16,6 +18,7 @@ public class SysDictType extends BaseEntity
/** 字典主键 */ /** 字典主键 */
@Excel(name = "字典主键") @Excel(name = "字典主键")
@Id
private Long dictId; private Long dictId;
/** 字典名称 */ /** 字典名称 */

View File

@ -6,6 +6,8 @@ import java.util.Date;
import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.base.BaseEntity; import com.ruoyi.common.base.BaseEntity;
import javax.persistence.Id;
/** /**
* 系统访问记录表 sys_logininfor * 系统访问记录表 sys_logininfor
* *
@ -17,6 +19,7 @@ public class SysLogininfor extends BaseEntity
/** ID */ /** ID */
@Excel(name = "序号") @Excel(name = "序号")
@Id
private Long infoId; private Long infoId;
/** 用户账号 */ /** 用户账号 */

View File

@ -6,6 +6,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.ruoyi.common.base.BaseEntity; import com.ruoyi.common.base.BaseEntity;
import javax.persistence.Id;
/** /**
* 菜单权限表 sys_menu * 菜单权限表 sys_menu
* *
@ -16,6 +18,7 @@ public class SysMenu extends BaseEntity
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 菜单ID */ /** 菜单ID */
@Id
private Long menuId; private Long menuId;
/** 菜单名称 */ /** 菜单名称 */

View File

@ -4,6 +4,8 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.base.BaseEntity; import com.ruoyi.common.base.BaseEntity;
import javax.persistence.Id;
/** /**
* 通知公告表 sys_notice * 通知公告表 sys_notice
* *
@ -14,6 +16,7 @@ public class SysNotice extends BaseEntity
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 公告ID */ /** 公告ID */
@Id
private Long noticeId; private Long noticeId;
/** 公告标题 */ /** 公告标题 */

View File

@ -6,6 +6,8 @@ import java.util.Date;
import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.base.BaseEntity; import com.ruoyi.common.base.BaseEntity;
import javax.persistence.Id;
/** /**
* 操作日志记录表 oper_log * 操作日志记录表 oper_log
* *
@ -17,6 +19,7 @@ public class SysOperLog extends BaseEntity
/** 日志主键 */ /** 日志主键 */
@Excel(name = "操作序号") @Excel(name = "操作序号")
@Id
private Long operId; private Long operId;
/** 操作模块 */ /** 操作模块 */

View File

@ -5,6 +5,8 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.base.BaseEntity; import com.ruoyi.common.base.BaseEntity;
import javax.persistence.Id;
/** /**
* 岗位表 sys_post * 岗位表 sys_post
* *
@ -16,6 +18,7 @@ public class SysPost extends BaseEntity
/** 岗位序号 */ /** 岗位序号 */
@Excel(name = "岗位序号") @Excel(name = "岗位序号")
@Id
private Long postId; private Long postId;
/** 岗位编码 */ /** 岗位编码 */

View File

@ -5,6 +5,8 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.base.BaseEntity; import com.ruoyi.common.base.BaseEntity;
import javax.persistence.Id;
/** /**
* 角色表 sys_role * 角色表 sys_role
* *
@ -16,6 +18,7 @@ public class SysRole extends BaseEntity
/** 角色ID */ /** 角色ID */
@Excel(name = "角色序号") @Excel(name = "角色序号")
@Id
private Long roleId; private Long roleId;
/** 角色名称 */ /** 角色名称 */

View File

@ -3,6 +3,8 @@ package com.ruoyi.system.domain;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import javax.persistence.Id;
/** /**
* 角色和部门关联 sys_role_dept * 角色和部门关联 sys_role_dept
* *
@ -11,6 +13,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
public class SysRoleDept public class SysRoleDept
{ {
/** 角色ID */ /** 角色ID */
@Id
private Long roleId; private Long roleId;
/** 部门ID */ /** 部门ID */

View File

@ -3,6 +3,8 @@ package com.ruoyi.system.domain;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import javax.persistence.Id;
/** /**
* 角色和菜单关联 sys_role_menu * 角色和菜单关联 sys_role_menu
* *
@ -11,6 +13,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
public class SysRoleMenu public class SysRoleMenu
{ {
/** 角色ID */ /** 角色ID */
@Id
private Long roleId; private Long roleId;
/** 菜单ID */ /** 菜单ID */

View File

@ -7,6 +7,8 @@ import java.util.List;
import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.base.BaseEntity; import com.ruoyi.common.base.BaseEntity;
import javax.persistence.Id;
/** /**
* 用户对象 sys_user * 用户对象 sys_user
* *
@ -18,6 +20,7 @@ public class SysUser extends BaseEntity
/** 用户ID */ /** 用户ID */
@Excel(name = "用户序号") @Excel(name = "用户序号")
@Id
private Long userId; private Long userId;
/** 部门ID */ /** 部门ID */

View File

@ -6,6 +6,8 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.base.BaseEntity; import com.ruoyi.common.base.BaseEntity;
import com.ruoyi.common.enums.OnlineStatus; import com.ruoyi.common.enums.OnlineStatus;
import javax.persistence.Id;
/** /**
* 当前在线会话 sys_user_online * 当前在线会话 sys_user_online
* *
@ -16,6 +18,7 @@ public class SysUserOnline extends BaseEntity
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 用户会话id */ /** 用户会话id */
@Id
private String sessionId; private String sessionId;
/** 部门名称 */ /** 部门名称 */

View File

@ -3,6 +3,8 @@ package com.ruoyi.system.domain;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import javax.persistence.Id;
/** /**
* 用户和岗位关联 sys_user_post * 用户和岗位关联 sys_user_post
* *
@ -11,6 +13,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
public class SysUserPost public class SysUserPost
{ {
/** 用户ID */ /** 用户ID */
@Id
private Long userId; private Long userId;
/** 岗位ID */ /** 岗位ID */

View File

@ -3,6 +3,8 @@ package com.ruoyi.system.domain;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import javax.persistence.Id;
/** /**
* 用户和角色关联 sys_user_role * 用户和角色关联 sys_user_role
* *
@ -11,6 +13,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
public class SysUserRole public class SysUserRole
{ {
/** 用户ID */ /** 用户ID */
@Id
private Long userId; private Long userId;
/** 角色ID */ /** 角色ID */

View File

@ -1,9 +1,10 @@
package com.ruoyi.agile.domain; package com.ruoyi.agile.domain;
import com.ruoyi.common.base.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.base.BaseEntity;
import javax.persistence.Id;
import java.math.BigDecimal; import java.math.BigDecimal;
/** /**
@ -17,6 +18,7 @@ public class GenTableColumn extends BaseEntity
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 编号 */ /** 编号 */
@Id
private String id; private String id;
/** 表名 */ /** 表名 */
private String tableName; private String tableName;

View File

@ -2,9 +2,6 @@ package com.ruoyi.agile.mapper;
import com.ruoyi.agile.domain.GenTable; import com.ruoyi.agile.domain.GenTable;
import com.ruoyi.framework.web.base.MyMapper; import com.ruoyi.framework.web.base.MyMapper;
import com.ruoyi.generator.domain.TableInfo;
import java.util.List;
/** /**
* 代码生成 数据层 * 代码生成 数据层

View File

@ -3,6 +3,8 @@ package com.ruoyi.generator.domain;
import com.ruoyi.common.json.JSON; import com.ruoyi.common.json.JSON;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import javax.persistence.Id;
/** /**
* ry数据库表列信息 * ry数据库表列信息
* *
@ -11,6 +13,7 @@ import com.ruoyi.common.utils.StringUtils;
public class ColumnInfo public class ColumnInfo
{ {
/** 字段名称 */ /** 字段名称 */
@Id
private String columnName; private String columnName;
/** 字段类型 */ /** 字段类型 */

View File

@ -4,6 +4,8 @@ import java.util.List;
import com.ruoyi.common.base.BaseEntity; import com.ruoyi.common.base.BaseEntity;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import javax.persistence.Id;
/** /**
* ry 数据库表 * ry 数据库表
* *
@ -14,6 +16,7 @@ public class TableInfo extends BaseEntity
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 表名称 */ /** 表名称 */
@Id
private String tableName; private String tableName;
/** 表描述 */ /** 表描述 */

View File

@ -27,112 +27,103 @@ import com.ruoyi.generator.util.VelocityInitializer;
/** /**
* 代码生成 服务层处理 * 代码生成 服务层处理
* *
* @author ruoyi * @author ruoyi
*/ */
@Service @Service
public class GenServiceImpl extends AbstractBaseServiceImpl<GenMapper,TableInfo> implements IGenService { public class GenServiceImpl extends AbstractBaseServiceImpl<GenMapper, TableInfo> implements IGenService {
private static final Logger log = LoggerFactory.getLogger(GenServiceImpl.class); private static final Logger log = LoggerFactory.getLogger( GenServiceImpl.class );
/** /**
* 查询ry数据库表信息 * 查询ry数据库表信息
* *
* @param tableInfo 表信息 * @param tableInfo 表信息
* @return 数据库表列表 * @return 数据库表列表
*/ */
@Override @Override
public List<TableInfo> selectTableList(TableInfo tableInfo) public List<TableInfo> selectTableList(TableInfo tableInfo) {
{
startPage(); startPage();
return mapper.selectTableList(tableInfo); return mapper.selectTableList( tableInfo );
} }
/** /**
* 生成代码 * 生成代码
* *
* @param tableName 表名称 * @param tableName 表名称
* @return 数据 * @return 数据
*/ */
@Override @Override
public byte[] generatorCode(String tableName) public byte[] generatorCode(String tableName) {
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream); ZipOutputStream zip = new ZipOutputStream( outputStream );
// 查询表信息 // 查询表信息
TableInfo table = mapper.selectTableByName(tableName); TableInfo table = mapper.selectTableByName( tableName );
// 查询列信息 // 查询列信息
List<ColumnInfo> columns = mapper.selectTableColumnsByName(tableName); List<ColumnInfo> columns = mapper.selectTableColumnsByName( tableName );
// 生成代码 // 生成代码
generatorCode(table, columns, zip); generatorCode( table, columns, zip );
IOUtils.closeQuietly(zip); IOUtils.closeQuietly( zip );
return outputStream.toByteArray(); return outputStream.toByteArray();
} }
/** /**
* 批量生成代码 * 批量生成代码
* *
* @param tableNames 表数组 * @param tableNames 表数组
* @return 数据 * @return 数据
*/ */
@Override @Override
public byte[] generatorCode(String[] tableNames) public byte[] generatorCode(String[] tableNames) {
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream); ZipOutputStream zip = new ZipOutputStream( outputStream );
for (String tableName : tableNames) for (String tableName : tableNames) {
{
// 查询表信息 // 查询表信息
TableInfo table = mapper.selectTableByName(tableName); TableInfo table = mapper.selectTableByName( tableName );
// 查询列信息 // 查询列信息
List<ColumnInfo> columns = mapper.selectTableColumnsByName(tableName); List<ColumnInfo> columns = mapper.selectTableColumnsByName( tableName );
// 生成代码 // 生成代码
generatorCode(table, columns, zip); generatorCode( table, columns, zip );
} }
IOUtils.closeQuietly(zip); IOUtils.closeQuietly( zip );
return outputStream.toByteArray(); return outputStream.toByteArray();
} }
/** /**
* 生成代码 * 生成代码
*/ */
public void generatorCode(TableInfo table, List<ColumnInfo> columns, ZipOutputStream zip) public void generatorCode(TableInfo table, List<ColumnInfo> columns, ZipOutputStream zip) {
{
// 表名转换成Java属性名 // 表名转换成Java属性名
String className = GenUtils.tableToJava(table.getTableName()); String className = GenUtils.tableToJava( table.getTableName() );
table.setClassName(className); table.setClassName( className );
table.setClassname(StringUtils.uncapitalize(className)); table.setClassname( StringUtils.uncapitalize( className ) );
// 列信息 // 列信息
table.setColumns(GenUtils.transColums(columns)); table.setColumns( GenUtils.transColums( columns ) );
// 设置主键 // 设置主键
table.setPrimaryKey(table.getColumnsLast()); table.setPrimaryKey( table.getColumnsLast() );
VelocityInitializer.initVelocity(); VelocityInitializer.initVelocity();
String packageName = Global.getPackageName(); String packageName = Global.getPackageName();
String moduleName = GenUtils.getModuleName(packageName); String moduleName = GenUtils.getModuleName( packageName );
VelocityContext context = GenUtils.getVelocityContext(table); VelocityContext context = GenUtils.getVelocityContext( table );
// 获取模板列表 // 获取模板列表
List<String> templates = GenUtils.getTemplates(); List<String> templates = GenUtils.getTemplates();
for (String template : templates) for (String template : templates) {
{
// 渲染模板 // 渲染模板
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
Template tpl = Velocity.getTemplate(template, Constants.UTF8); Template tpl = Velocity.getTemplate( template, Constants.UTF8 );
tpl.merge(context, sw); tpl.merge( context, sw );
try try {
{
// 添加到zip // 添加到zip
zip.putNextEntry(new ZipEntry(GenUtils.getFileName(template, table, moduleName))); zip.putNextEntry( new ZipEntry( GenUtils.getFileName( template, table, moduleName ) ) );
IOUtils.write(sw.toString(), zip, Constants.UTF8); IOUtils.write( sw.toString(), zip, Constants.UTF8 );
IOUtils.closeQuietly(sw); IOUtils.closeQuietly( sw );
zip.closeEntry(); zip.closeEntry();
} } catch (IOException e) {
catch (IOException e) log.error( "渲染模板失败,表名:" + table.getTableName(), e );
{
log.error("渲染模板失败,表名:" + table.getTableName(), e);
} }
} }
} }

View File

@ -2,7 +2,7 @@
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.agile.mapper.GenTableColumnMapper"> <mapper namespace="com.ruoyi.agile.mapper.GenTableColumnAllMapper">
<resultMap type="GenTableColumn" id="GenTableColumnResult"> <resultMap type="GenTableColumn" id="GenTableColumnResult">
<result property="id" column="id" /> <result property="id" column="id" />

View File

@ -2,7 +2,7 @@
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.agile.mapper.GenTableMapper"> <mapper namespace="com.ruoyi.agile.mapper.GenTableAllMapper">
<resultMap type="GenTable" id="GenTableResult"> <resultMap type="GenTable" id="GenTableResult">
<result property="id" column="id" /> <result property="id" column="id" />

View File

@ -49,7 +49,7 @@ public class ${className}Controller extends BaseController
@ResponseBody @ResponseBody
public TableDataInfo list(${className} ${classname}) public TableDataInfo list(${className} ${classname})
{ {
List<${className}> list = ${classname}Service.select${className}List(${classname}); List<${className}> list = ${classname}Service.select${className}Page(${classname});
return getDataTable(list); return getDataTable(list);
} }
@ -85,7 +85,7 @@ public class ${className}Controller extends BaseController
@ResponseBody @ResponseBody
public AjaxResult addSave(${className} ${classname}) public AjaxResult addSave(${className} ${classname})
{ {
return toAjax(${classname}Service.insert${className}(${classname})); return toAjax(${classname}Service.insert(${classname}));
} }
/** /**
@ -94,7 +94,7 @@ public class ${className}Controller extends BaseController
@GetMapping("/edit/{${primaryKey.attrname}}") @GetMapping("/edit/{${primaryKey.attrname}}")
public String edit(@PathVariable("${primaryKey.attrname}") ${primaryKey.attrType} ${primaryKey.attrname}, ModelMap mmap) public String edit(@PathVariable("${primaryKey.attrname}") ${primaryKey.attrType} ${primaryKey.attrname}, ModelMap mmap)
{ {
${className} ${classname} = ${classname}Service.select${className}ById(${primaryKey.attrname}); ${className} ${classname} = ${classname}Service.selectById(${primaryKey.attrname});
mmap.put("${classname}", ${classname}); mmap.put("${classname}", ${classname});
return prefix + "/edit"; return prefix + "/edit";
} }
@ -108,7 +108,7 @@ public class ${className}Controller extends BaseController
@ResponseBody @ResponseBody
public AjaxResult editSave(${className} ${classname}) public AjaxResult editSave(${className} ${classname})
{ {
return toAjax(${classname}Service.update${className}(${classname})); return toAjax(${classname}Service.updateById(${classname}));
} }
/** /**
@ -120,7 +120,7 @@ public class ${className}Controller extends BaseController
@ResponseBody @ResponseBody
public AjaxResult remove(String ids) public AjaxResult remove(String ids)
{ {
return toAjax(${classname}Service.delete${className}ByIds(ids)); return toAjax(${classname}Service.deleteByIds(ids));
} }
} }

View File

@ -12,14 +12,7 @@ import com.ruoyi.framework.web.base.MyMapper;
*/ */
public interface ${className}Mapper extends MyMapper<${className}> public interface ${className}Mapper extends MyMapper<${className}>
{ {
/**
* 查询${tableComment}信息
*
* @param ${primaryKey.attrname} ${tableComment}ID
* @return ${tableComment}信息
*/
public ${className} select${className}ById(${primaryKey.attrType} ${primaryKey.attrname});
/** /**
* 查询${tableComment}列表 * 查询${tableComment}列表
* *
@ -28,36 +21,4 @@ public interface ${className}Mapper extends MyMapper<${className}>
*/ */
public List<${className}> select${className}List(${className} ${classname}); public List<${className}> select${className}List(${className} ${classname});
/**
* 新增${tableComment}
*
* @param ${classname} ${tableComment}信息
* @return 结果
*/
public int insert${className}(${className} ${classname});
/**
* 修改${tableComment}
*
* @param ${classname} ${tableComment}信息
* @return 结果
*/
public int update${className}(${className} ${classname});
/**
* 删除${tableComment}
*
* @param ${primaryKey.attrname} ${tableComment}ID
* @return 结果
*/
public int delete${className}ById(${primaryKey.attrType} ${primaryKey.attrname});
/**
* 批量删除${tableComment}
*
* @param ${primaryKey.attrname}s 需要删除的数据ID
* @return 结果
*/
public int delete${className}ByIds(String[] ${primaryKey.attrname}s);
} }

View File

@ -12,43 +12,19 @@ import com.ruoyi.framework.web.base.AbstractBaseService;
public interface I${className}Service extends AbstractBaseService<${className}> public interface I${className}Service extends AbstractBaseService<${className}>
{ {
/** /**
* 查询${tableComment}信息 * 查询${tableComment}分页列表
* *
* @param ${primaryKey.attrname} ${tableComment}ID
* @return ${tableComment}信息
*/
public ${className} select${className}ById(${primaryKey.attrType} ${primaryKey.attrname});
/**
* 查询${tableComment}列表
*
* @param ${classname} ${tableComment}信息 * @param ${classname} ${tableComment}信息
* @return ${tableComment}集合 * @return ${tableComment}集合
*/ */
public List<${className}> select${className}List(${className} ${classname}); public List<${className}> select${className}Page(${className} ${classname});
/**
/** * 查询${tableComment}列表
* 新增${tableComment} *
*
* @param ${classname} ${tableComment}信息 * @param ${classname} ${tableComment}信息
* @return 结果 * @return ${tableComment}集合
*/ */
public int insert${className}(${className} ${classname}); public List<${className}> select${className}List(${className} ${classname});
/**
* 修改${tableComment}
*
* @param ${classname} ${tableComment}信息
* @return 结果
*/
public int update${className}(${className} ${classname});
/**
* 删除${tableComment}信息
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int delete${className}ByIds(String ids);
} }

View File

@ -20,17 +20,6 @@ public class ${className}ServiceImpl extends AbstractBaseServiceImpl<${className
@Autowired @Autowired
private ${className}Mapper ${classname}Mapper; private ${className}Mapper ${classname}Mapper;
/**
* 查询${tableComment}信息
*
* @param ${primaryKey.attrname} ${tableComment}ID
* @return ${tableComment}信息
*/
@Override
public ${className} select${className}ById(${primaryKey.attrType} ${primaryKey.attrname})
{
return ${classname}Mapper.select${className}ById(${primaryKey.attrname});
}
/** /**
* 查询${tableComment}列表 * 查询${tableComment}列表
@ -41,44 +30,19 @@ public class ${className}ServiceImpl extends AbstractBaseServiceImpl<${className
@Override @Override
public List<${className}> select${className}List(${className} ${classname}) public List<${className}> select${className}List(${className} ${classname})
{ {
startPage();
return ${classname}Mapper.select${className}List(${classname}); return ${classname}Mapper.select${className}List(${classname});
} }
/** /**
* 新增${tableComment} * 查询${tableComment}分页列表
* *
* @param ${classname} ${tableComment}信息 * @param ${classname} ${tableComment}信息
* @return 结果 * @return ${tableComment}集合
*/ */
@Override @Override
public int insert${className}(${className} ${classname}) public List<${className}> select${className}Page(${className} ${classname})
{ {
return ${classname}Mapper.insert${className}(${classname}); startPage();
} return ${classname}Mapper.select${className}List(${classname});
}
/**
* 修改${tableComment}
*
* @param ${classname} ${tableComment}信息
* @return 结果
*/
@Override
public int update${className}(${className} ${classname})
{
return ${classname}Mapper.update${className}(${classname});
}
/**
* 删除${tableComment}对象
*
* @param ids 需要删除的数据ID
* @return 结果
*/
@Override
public int delete${className}ByIds(String ids)
{
return ${classname}Mapper.delete${className}ByIds(Convert.toStrArray(ids));
}
} }

View File

@ -5,6 +5,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.base.BaseEntity; import com.ruoyi.common.base.BaseEntity;
#foreach ($column in $columns) #foreach ($column in $columns)
#if($column.attrType == 'Date') #if($column.attrType == 'Date')
import javax.persistence.Id;
import java.util.Date; import java.util.Date;
#break #break
#end #end
@ -22,6 +23,7 @@ public class ${className}
#foreach ($column in $columns) #foreach ($column in $columns)
/** $column.columnComment */ /** $column.columnComment */
@Id
private $column.attrType $column.attrname; private $column.attrType $column.attrname;
#end #end

View File

@ -11,62 +11,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap> </resultMap>
<sql id="select${className}Vo"> <sql id="select${className}Vo">
select#foreach($column in $columns) $column.columnName#if($velocityCount != $columns.size()),#end#end from ${tableName} #foreach($column in $columns) $column.columnName#if($velocityCount != $columns.size()),#end#end
</sql> </sql>
<select id="select${className}List" parameterType="${className}" resultMap="${className}Result"> <select id="select${className}List" parameterType="${className}" resultMap="${className}Result">
select
<include refid="select${className}Vo"/> <include refid="select${className}Vo"/>
from ${tableName}
<where> <where>
#foreach($column in $columns) #foreach($column in $columns)
<if test="$column.attrname != null #if($column.attrType == 'String' ) and $column.attrname.trim() != '' #end"> and $column.columnName = #{$column.attrname}</if> <if test="$column.attrname != null #if($column.attrType == 'String' ) and $column.attrname.trim() != '' #end"> and $column.columnName = #{$column.attrname}</if>
#end #end
</where> </where>
</select> </select>
<select id="select${className}ById" parameterType="${primaryKey.attrType}" resultMap="${className}Result">
<include refid="select${className}Vo"/>
where ${primaryKey.columnName} = #{${primaryKey.attrname}}
</select>
<insert id="insert${className}" parameterType="${className}"#if($primaryKey.extra == 'auto_increment') useGeneratedKeys="true" keyProperty="$primaryKey.attrname"#end>
insert into ${tableName}
<trim prefix="(" suffix=")" suffixOverrides=",">
#foreach($column in $columns)
#if($column.columnName != $primaryKey.columnName || $primaryKey.extra != 'auto_increment')
<if test="$column.attrname != null #if($column.attrType == 'String' ) and $column.attrname != '' #end ">$column.columnName,</if>
#end
#end
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#foreach($column in $columns)
#if($column.columnName != $primaryKey.columnName || $primaryKey.extra != 'auto_increment')
<if test="$column.attrname != null #if($column.attrType == 'String' ) and $column.attrname != '' #end ">#{$column.attrname},</if>
#end
#end
</trim>
</insert>
<update id="update${className}" parameterType="${className}">
update ${tableName}
<trim prefix="SET" suffixOverrides=",">
#foreach($column in $columns)
#if($column.columnName != $primaryKey.columnName)
<if test="$column.attrname != null #if($column.attrType == 'String' ) and $column.attrname != '' #end ">$column.columnName = #{$column.attrname},</if>
#end
#end
</trim>
where ${primaryKey.columnName} = #{${primaryKey.attrname}}
</update>
<delete id="delete${className}ById" parameterType="${primaryKey.attrType}">
delete from ${tableName} where ${primaryKey.columnName} = #{${primaryKey.attrname}}
</delete>
<delete id="delete${className}ByIds" parameterType="String">
delete from ${tableName} where ${primaryKey.columnName} in
<foreach item="${primaryKey.attrname}" collection="array" open="(" separator="," close=")">
#{${primaryKey.attrname}}
</foreach>
</delete>
</mapper> </mapper>