提交 ee89a002 authored 作者: 李秋林's avatar 李秋林

修改后端代码生成模板;集成Mybatis-plus;分页规范修改

上级 176304cf
...@@ -81,6 +81,15 @@ ...@@ -81,6 +81,15 @@
<version>${druid-spring-boot-starter.version}</version> <version>${druid-spring-boot-starter.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-annotation</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
package com.sfa.gen; package com.sfa.gen;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.sfa.common.security.annotation.EnableCustomConfig; import com.sfa.common.security.annotation.EnableCustomConfig;
...@@ -13,6 +14,7 @@ import com.sfa.common.security.annotation.EnableRyFeignClients; ...@@ -13,6 +14,7 @@ import com.sfa.common.security.annotation.EnableRyFeignClients;
@EnableCustomConfig @EnableCustomConfig
@EnableRyFeignClients @EnableRyFeignClients
@SpringBootApplication @SpringBootApplication
@MapperScan("com.sfa.gen.mapper")
public class SfaGenApplication public class SfaGenApplication
{ {
public static void main(String[] args) public static void main(String[] args)
......
package com.sfa.gen.config.mysql;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author : liqiulin
* @date : 2024-04-25 13
* @describe :
*/
@Configuration
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(){
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return interceptor;
}
}
\ No newline at end of file
package com.sfa.gen.controller; package com.sfa.gen.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.druid.DbType; import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.SQLUtils; import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement; import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement; import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
import com.sfa.common.core.text.Convert; import com.sfa.common.core.text.Convert;
import com.sfa.common.core.utils.sql.SqlUtil;
import com.sfa.common.core.web.controller.BaseController; import com.sfa.common.core.web.controller.BaseController;
import com.sfa.common.core.web.domain.AjaxResult; import com.sfa.common.core.web.domain.AjaxResult;
import com.sfa.common.core.web.page.TableDataInfo; import com.sfa.common.core.web.domain.PageInfo;
import com.sfa.common.log.annotation.Log; import com.sfa.common.log.annotation.Log;
import com.sfa.common.log.enums.BusinessType; import com.sfa.common.log.enums.BusinessType;
import com.sfa.common.security.annotation.RequiresPermissions; import com.sfa.common.security.annotation.RequiresPermissions;
import com.sfa.common.core.utils.sql.SqlUtil;
import com.sfa.gen.domain.GenTable; import com.sfa.gen.domain.GenTable;
import com.sfa.gen.domain.GenTableColumn; import com.sfa.gen.domain.GenTableColumn;
import com.sfa.gen.service.IGenTableColumnService; import com.sfa.gen.service.IGenTableColumnService;
import com.sfa.gen.service.IGenTableService; import com.sfa.gen.service.IGenTableService;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* 代码生成 操作处理 * 代码生成 操作处理
...@@ -55,11 +48,9 @@ public class GenController extends BaseController ...@@ -55,11 +48,9 @@ public class GenController extends BaseController
*/ */
@RequiresPermissions("tool:gen:list") @RequiresPermissions("tool:gen:list")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo genList(GenTable genTable) public PageInfo genList(GenTable genTable)
{ {
startPage(); return genTableService.selectGenTableList(genTable);
List<GenTable> list = genTableService.selectGenTableList(genTable);
return getDataTable(list);
} }
/** /**
...@@ -120,24 +111,18 @@ public class GenController extends BaseController ...@@ -120,24 +111,18 @@ public class GenController extends BaseController
*/ */
@RequiresPermissions("tool:gen:list") @RequiresPermissions("tool:gen:list")
@GetMapping("/db/list") @GetMapping("/db/list")
public TableDataInfo dataList(GenTable genTable) public PageInfo dataList(GenTable genTable)
{ {
startPage(); return genTableService.selectDbTableList(genTable);
List<GenTable> list = genTableService.selectDbTableList(genTable);
return getDataTable(list);
} }
/** /**
* 查询数据表字段列表 * 查询数据表字段列表
*/ */
@GetMapping(value = "/column/{tableId}") @GetMapping(value = "/column/{tableId}")
public TableDataInfo columnList(Long tableId) public List<GenTableColumn> columnList(Long tableId)
{ {
TableDataInfo dataInfo = new TableDataInfo(); return genTableColumnService.selectGenTableColumnListByTableId(tableId);
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
dataInfo.setRows(list);
dataInfo.setTotal(list.size());
return dataInfo;
} }
/** /**
......
...@@ -3,6 +3,15 @@ package com.sfa.gen.domain; ...@@ -3,6 +3,15 @@ package com.sfa.gen.domain;
import java.util.List; import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sfa.common.core.web.domain.BaseDo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import com.sfa.common.core.constant.GenConstants; import com.sfa.common.core.constant.GenConstants;
import com.sfa.common.core.utils.StringUtils; import com.sfa.common.core.utils.StringUtils;
...@@ -13,11 +22,16 @@ import com.sfa.common.core.web.domain.BaseEntity; ...@@ -13,11 +22,16 @@ import com.sfa.common.core.web.domain.BaseEntity;
* *
* @author ruoyi * @author ruoyi
*/ */
public class GenTable extends BaseEntity @NoArgsConstructor
@AllArgsConstructor
@Data
@TableName(value = "gen_table")
public class GenTable extends BaseDo
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 编号 */ /** 编号 */
@TableId(type = IdType.AUTO)
private Long tableId; private Long tableId;
/** 表名称 */ /** 表名称 */
...@@ -71,12 +85,15 @@ public class GenTable extends BaseEntity ...@@ -71,12 +85,15 @@ public class GenTable extends BaseEntity
private String genPath; private String genPath;
/** 主键信息 */ /** 主键信息 */
@TableField(exist = false)
private GenTableColumn pkColumn; private GenTableColumn pkColumn;
/** 子表信息 */ /** 子表信息 */
@TableField(exist = false)
private GenTable subTable; private GenTable subTable;
/** 表列信息 */ /** 表列信息 */
@TableField(exist = false)
@Valid @Valid
private List<GenTableColumn> columns; private List<GenTableColumn> columns;
...@@ -84,259 +101,24 @@ public class GenTable extends BaseEntity ...@@ -84,259 +101,24 @@ public class GenTable extends BaseEntity
private String options; private String options;
/** 树编码字段 */ /** 树编码字段 */
@TableField(exist = false)
private String treeCode; private String treeCode;
/** 树父编码字段 */ /** 树父编码字段 */
@TableField(exist = false)
private String treeParentCode; private String treeParentCode;
/** 树名称字段 */ /** 树名称字段 */
@TableField(exist = false)
private String treeName; private String treeName;
/** 上级菜单ID字段 */ /** 上级菜单ID字段 */
@TableField(exist = false)
private String parentMenuId; private String parentMenuId;
/** 上级菜单名称字段 */ /** 上级菜单名称字段 */
@TableField(exist = false)
private String parentMenuName; private String parentMenuName;
public Long getTableId()
{
return tableId;
}
public void setTableId(Long tableId)
{
this.tableId = tableId;
}
public String getTableName()
{
return tableName;
}
public void setTableName(String tableName)
{
this.tableName = tableName;
}
public String getTableComment()
{
return tableComment;
}
public void setTableComment(String tableComment)
{
this.tableComment = tableComment;
}
public String getSubTableName()
{
return subTableName;
}
public void setSubTableName(String subTableName)
{
this.subTableName = subTableName;
}
public String getSubTableFkName()
{
return subTableFkName;
}
public void setSubTableFkName(String subTableFkName)
{
this.subTableFkName = subTableFkName;
}
public String getClassName()
{
return className;
}
public void setClassName(String className)
{
this.className = className;
}
public String getTplCategory()
{
return tplCategory;
}
public void setTplCategory(String tplCategory)
{
this.tplCategory = tplCategory;
}
public String getTplWebType()
{
return tplWebType;
}
public void setTplWebType(String tplWebType)
{
this.tplWebType = tplWebType;
}
public String getPackageName()
{
return packageName;
}
public void setPackageName(String packageName)
{
this.packageName = packageName;
}
public String getModuleName()
{
return moduleName;
}
public void setModuleName(String moduleName)
{
this.moduleName = moduleName;
}
public String getBusinessName()
{
return businessName;
}
public void setBusinessName(String businessName)
{
this.businessName = businessName;
}
public String getFunctionName()
{
return functionName;
}
public void setFunctionName(String functionName)
{
this.functionName = functionName;
}
public String getFunctionAuthor()
{
return functionAuthor;
}
public void setFunctionAuthor(String functionAuthor)
{
this.functionAuthor = functionAuthor;
}
public String getGenType()
{
return genType;
}
public void setGenType(String genType)
{
this.genType = genType;
}
public String getGenPath()
{
return genPath;
}
public void setGenPath(String genPath)
{
this.genPath = genPath;
}
public GenTableColumn getPkColumn()
{
return pkColumn;
}
public void setPkColumn(GenTableColumn pkColumn)
{
this.pkColumn = pkColumn;
}
public GenTable getSubTable()
{
return subTable;
}
public void setSubTable(GenTable subTable)
{
this.subTable = subTable;
}
public List<GenTableColumn> getColumns()
{
return columns;
}
public void setColumns(List<GenTableColumn> columns)
{
this.columns = columns;
}
public String getOptions()
{
return options;
}
public void setOptions(String options)
{
this.options = options;
}
public String getTreeCode()
{
return treeCode;
}
public void setTreeCode(String treeCode)
{
this.treeCode = treeCode;
}
public String getTreeParentCode()
{
return treeParentCode;
}
public void setTreeParentCode(String treeParentCode)
{
this.treeParentCode = treeParentCode;
}
public String getTreeName()
{
return treeName;
}
public void setTreeName(String treeName)
{
this.treeName = treeName;
}
public String getParentMenuId()
{
return parentMenuId;
}
public void setParentMenuId(String parentMenuId)
{
this.parentMenuId = parentMenuId;
}
public String getParentMenuName()
{
return parentMenuName;
}
public void setParentMenuName(String parentMenuName)
{
this.parentMenuName = parentMenuName;
}
public boolean isSub() public boolean isSub()
{ {
return isSub(this.tplCategory); return isSub(this.tplCategory);
......
package com.sfa.gen.mapper; package com.sfa.gen.mapper;
import java.util.List; import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sfa.gen.domain.GenTable; import com.sfa.gen.domain.GenTable;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
/** /**
...@@ -12,7 +15,7 @@ import org.springframework.stereotype.Repository; ...@@ -12,7 +15,7 @@ import org.springframework.stereotype.Repository;
*/ */
@Repository @Repository
@Mapper @Mapper
public interface GenTableMapper public interface GenTableMapper extends BaseMapper<GenTable>
{ {
/** /**
* 查询业务列表 * 查询业务列表
...@@ -92,4 +95,8 @@ public interface GenTableMapper ...@@ -92,4 +95,8 @@ public interface GenTableMapper
* @return 结果 * @return 结果
*/ */
public int createTable(String sql); public int createTable(String sql);
List<GenTable> selectDbTablePage(@Param("genTable") GenTable genTable, @Param("skipNum") int skipNum, @Param("pageSize") int pageSize);
Integer selectDbTableCount(GenTable genTable);
} }
\ No newline at end of file
package com.sfa.gen.service; package com.sfa.gen.service;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sfa.common.core.constant.Constants; import com.sfa.common.core.constant.Constants;
import com.sfa.common.core.constant.GenConstants; import com.sfa.common.core.constant.GenConstants;
import com.sfa.common.core.exception.ServiceException; import com.sfa.common.core.exception.ServiceException;
import com.sfa.common.core.text.CharsetKit; import com.sfa.common.core.text.CharsetKit;
import com.sfa.common.core.utils.StringUtils; import com.sfa.common.core.utils.StringUtils;
import com.sfa.common.core.web.domain.PageInfo;
import com.sfa.common.core.web.page.TableSupport;
import com.sfa.common.security.utils.SecurityUtils; import com.sfa.common.security.utils.SecurityUtils;
import com.sfa.gen.domain.GenTable; import com.sfa.gen.domain.GenTable;
import com.sfa.gen.domain.GenTableColumn; import com.sfa.gen.domain.GenTableColumn;
...@@ -36,6 +19,28 @@ import com.sfa.gen.mapper.GenTableMapper; ...@@ -36,6 +19,28 @@ import com.sfa.gen.mapper.GenTableMapper;
import com.sfa.gen.util.GenUtils; import com.sfa.gen.util.GenUtils;
import com.sfa.gen.util.VelocityInitializer; import com.sfa.gen.util.VelocityInitializer;
import com.sfa.gen.util.VelocityUtils; import com.sfa.gen.util.VelocityUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/** /**
* 业务 服务层实现 * 业务 服务层实现
...@@ -74,9 +79,23 @@ public class GenTableServiceImpl implements IGenTableService ...@@ -74,9 +79,23 @@ public class GenTableServiceImpl implements IGenTableService
* @return 业务集合 * @return 业务集合
*/ */
@Override @Override
public List<GenTable> selectGenTableList(GenTable genTable) public PageInfo selectGenTableList(GenTable genTable)
{ {
return genTableMapper.selectGenTableList(genTable); LambdaQueryWrapper<GenTable> qw = buildWrapper(genTable);
Page<GenTable> pageR = genTableMapper.selectPage(TableSupport.pageI(), qw);
PageInfo<GenTable> pageInfo = new PageInfo<>(pageR);
return pageInfo;
}
private LambdaQueryWrapper<GenTable> buildWrapper(GenTable genTable) {
LambdaQueryWrapper<GenTable> qw = new LambdaQueryWrapper<>();
if (StringUtils.isNotBlank(genTable.getTableName())){
qw.like(true,GenTable::getTableName,genTable.getTableName());
}
if (StringUtils.isNotBlank(genTable.getTableComment())){
qw.like(true,GenTable::getTableComment,genTable.getTableComment());
}
return qw;
} }
/** /**
...@@ -86,9 +105,14 @@ public class GenTableServiceImpl implements IGenTableService ...@@ -86,9 +105,14 @@ public class GenTableServiceImpl implements IGenTableService
* @return 数据库表集合 * @return 数据库表集合
*/ */
@Override @Override
public List<GenTable> selectDbTableList(GenTable genTable) public PageInfo selectDbTableList(GenTable genTable)
{ {
return genTableMapper.selectDbTableList(genTable); PageInfo<GenTable> pageInfo = TableSupport.pageInfo();
List<GenTable> dos = genTableMapper.selectDbTablePage(genTable,pageInfo.getSkipNum(),pageInfo.getPageSize());
Integer count = genTableMapper.selectDbTableCount(genTable);
pageInfo.setRows(dos);
pageInfo.setTotal(count);
return pageInfo;
} }
/** /**
...@@ -124,7 +148,8 @@ public class GenTableServiceImpl implements IGenTableService ...@@ -124,7 +148,8 @@ public class GenTableServiceImpl implements IGenTableService
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateGenTable(GenTable genTable) public void updateGenTable(GenTable genTable)
{ {
String options = JSON.toJSONString(genTable.getParams()); // String options = JSON.toJSONString(genTable.getParams());
String options = JSON.toJSONString(genTable);
genTable.setOptions(options); genTable.setOptions(options);
int row = genTableMapper.updateGenTable(genTable); int row = genTableMapper.updateGenTable(genTable);
if (row > 0) if (row > 0)
...@@ -412,7 +437,8 @@ public class GenTableServiceImpl implements IGenTableService ...@@ -412,7 +437,8 @@ public class GenTableServiceImpl implements IGenTableService
{ {
if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) if (GenConstants.TPL_TREE.equals(genTable.getTplCategory()))
{ {
String options = JSON.toJSONString(genTable.getParams()); // String options = JSON.toJSONString(genTable.getParams());
String options = JSON.toJSONString(genTable);
JSONObject paramsObj = JSON.parseObject(options); JSONObject paramsObj = JSON.parseObject(options);
if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE)))
{ {
......
...@@ -2,6 +2,8 @@ package com.sfa.gen.service; ...@@ -2,6 +2,8 @@ package com.sfa.gen.service;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.sfa.common.core.web.domain.PageInfo;
import com.sfa.gen.domain.GenTable; import com.sfa.gen.domain.GenTable;
/** /**
...@@ -17,7 +19,7 @@ public interface IGenTableService ...@@ -17,7 +19,7 @@ public interface IGenTableService
* @param genTable 业务信息 * @param genTable 业务信息
* @return 业务集合 * @return 业务集合
*/ */
public List<GenTable> selectGenTableList(GenTable genTable); public PageInfo selectGenTableList(GenTable genTable);
/** /**
* 查询据库列表 * 查询据库列表
...@@ -25,7 +27,7 @@ public interface IGenTableService ...@@ -25,7 +27,7 @@ public interface IGenTableService
* @param genTable 业务信息 * @param genTable 业务信息
* @return 数据库表集合 * @return 数据库表集合
*/ */
public List<GenTable> selectDbTableList(GenTable genTable); public PageInfo selectDbTableList(GenTable genTable);
/** /**
* 查询据库列表 * 查询据库列表
......
...@@ -194,5 +194,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -194,5 +194,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{tableId} #{tableId}
</foreach> </foreach>
</delete> </delete>
<select id="selectDbTableCount" parameterType="com.sfa.gen.domain.GenTable" resultType="integer">
select count(*) from information_schema.tables
where table_schema = (select database())
AND table_name NOT LIKE 'qrtz\_%' AND table_name NOT LIKE 'gen\_%'
AND table_name NOT IN (select table_name from gen_table)
<if test="tableName != null and tableName != ''">
AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
</if>
<if test="tableComment != null and tableComment != ''">
AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
</if>
</select>
<select id="selectDbTablePage" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables
where table_schema = (select database())
AND table_name NOT LIKE 'qrtz\_%' AND table_name NOT LIKE 'gen\_%'
AND table_name NOT IN (select table_name from gen_table)
<if test="genTable.tableName != null and genTable.tableName != ''">
AND lower(table_name) like lower(concat('%', #{genTable.tableName}, '%'))
</if>
<if test="genTable.tableComment != null and genTable.tableComment != ''">
AND lower(table_comment) like lower(concat('%', #{genTable.tableComment}, '%'))
</if>
order by create_time desc
limit #{skipNum},#{pageSize};
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.PathVariable; ...@@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.sfa.common.core.web.domain.PageInfo;
import com.sfa.common.log.annotation.Log; import com.sfa.common.log.annotation.Log;
import com.sfa.common.log.enums.BusinessType; import com.sfa.common.log.enums.BusinessType;
import com.sfa.common.security.annotation.RequiresPermissions; import com.sfa.common.security.annotation.RequiresPermissions;
...@@ -44,11 +45,9 @@ public class ${ClassName}Controller extends BaseController ...@@ -44,11 +45,9 @@ public class ${ClassName}Controller extends BaseController
@RequiresPermissions("${permissionPrefix}:list") @RequiresPermissions("${permissionPrefix}:list")
@GetMapping("/list") @GetMapping("/list")
#if($table.crud || $table.sub) #if($table.crud || $table.sub)
public TableDataInfo list(${ClassName} ${className}) public PageInfo list(${ClassName} ${className})
{ {
startPage(); return ${className}Service.select${ClassName}page(${className});
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
return getDataTable(list);
} }
#elseif($table.tree) #elseif($table.tree)
public AjaxResult list(${ClassName} ${className}) public AjaxResult list(${ClassName} ${className})
......
...@@ -3,9 +3,12 @@ package ${packageName}.domain; ...@@ -3,9 +3,12 @@ package ${packageName}.domain;
#foreach ($import in $importList) #foreach ($import in $importList)
import ${import}; import ${import};
#end #end
import com.baomidou.mybatisplus.annotation.TableName;
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.sfa.common.core.annotation.Excel; import com.sfa.common.core.annotation.Excel;
import java.util.Date;
import lombok.Data;
#if($table.crud || $table.sub) #if($table.crud || $table.sub)
import com.sfa.common.core.web.domain.BaseEntity; import com.sfa.common.core.web.domain.BaseEntity;
#elseif($table.tree) #elseif($table.tree)
...@@ -19,10 +22,12 @@ import com.sfa.common.core.web.domain.TreeEntity; ...@@ -19,10 +22,12 @@ import com.sfa.common.core.web.domain.TreeEntity;
* @date ${datetime} * @date ${datetime}
*/ */
#if($table.crud || $table.sub) #if($table.crud || $table.sub)
#set($Entity="BaseEntity") #set($Entity="BaseDo")
#elseif($table.tree) #elseif($table.tree)
#set($Entity="TreeEntity") #set($Entity="TreeEntity")
#end #end
@TableName(value ="${tableName}")
@Data
public class ${ClassName} extends ${Entity} public class ${ClassName} extends ${Entity}
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
package ${packageName}.mapper; package ${packageName}.mapper;
import java.util.List; import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import ${packageName}.domain.${ClassName}; import ${packageName}.domain.${ClassName};
#if($table.sub) #if($table.sub)
import ${packageName}.domain.${subClassName}; import ${packageName}.domain.${subClassName};
...@@ -12,7 +15,9 @@ import ${packageName}.domain.${subClassName}; ...@@ -12,7 +15,9 @@ import ${packageName}.domain.${subClassName};
* @author ${author} * @author ${author}
* @date ${datetime} * @date ${datetime}
*/ */
public interface ${ClassName}Mapper @Repository
@Mapper
public interface ${ClassName}Mapper extends BaseMapper<${ClassName}>
{ {
/** /**
* 查询${functionName} * 查询${functionName}
......
package ${packageName}.service; package ${packageName}.service;
import java.util.List; import java.util.List;
import com.sfa.common.core.web.domain.PageInfo;
import ${packageName}.domain.${ClassName}; import ${packageName}.domain.${ClassName};
/** /**
...@@ -25,7 +26,7 @@ public interface I${ClassName}Service ...@@ -25,7 +26,7 @@ public interface I${ClassName}Service
* @param ${className} ${functionName} * @param ${className} ${functionName}
* @return ${functionName}集合 * @return ${functionName}集合
*/ */
public List<${ClassName}> select${ClassName}List(${ClassName} ${className}); public PageInfo select${ClassName}page(${ClassName} ${className});
/** /**
* 新增${functionName} * 新增${functionName}
......
package ${packageName}.service.impl; package ${packageName}.service.impl;
import java.util.List; import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sfa.common.core.web.domain.PageInfo;
import com.sfa.common.core.web.page.TableSupport;
#foreach ($column in $columns) #foreach ($column in $columns)
#if($column.javaField == 'createTime' || $column.javaField == 'updateTime') #if($column.javaField == 'createTime' || $column.javaField == 'updateTime')
import com.sfa.common.core.utils.DateUtils; import com.sfa.common.core.utils.DateUtils;
...@@ -50,9 +54,17 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service ...@@ -50,9 +54,17 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
* @return ${functionName} * @return ${functionName}
*/ */
@Override @Override
public List<${ClassName}> select${ClassName}List(${ClassName} ${className}) public List<${ClassName}> select${ClassName}page(${ClassName} ${className})
{ {
return ${className}Mapper.select${ClassName}List(${className}); LambdaQueryWrapper<${ClassName}> qw = buildWrapper(${className});
Page<${ClassName}> pageR = ${className}Mapper.selectPage(TableSupport.pageI(), qw);
PageInfo<${ClassName}> pageInfo = new PageInfo<>(pageR);
return pageInfo;
}
private LambdaQueryWrapper<${ClassName}> buildWrapper(${ClassName} ${className}) {
LambdaQueryWrapper<${ClassName}> qw = new LambdaQueryWrapper<>();
return qw;
} }
/** /**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论