生成的代码改为 mybatis-plus 格式,还不支持分页查询

pull/64/head
陈云志 5 years ago
parent dab94fa885
commit 3d0f8d681e

@ -38,8 +38,8 @@ dependencies {
implementation "org.apache.commons:commons-lang3:3.11" implementation "org.apache.commons:commons-lang3:3.11"
implementation "io.springfox:springfox-swagger-ui:2.9.2" implementation "io.springfox:springfox-swagger-ui:2.9.2"
implementation "org.mariadb.jdbc:mariadb-java-client:2.7.1" implementation "org.mariadb.jdbc:mariadb-java-client:2.7.1"
implementation "org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.4" // implementation "org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.4"
implementation 'com.baomidou:mybatis-plus-boot-starter:3.4.1'
implementation "com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-config:${alibabaCloud}" implementation "com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-config:${alibabaCloud}"
implementation "com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery:${alibabaCloud}" implementation "com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery:${alibabaCloud}"
implementation "com.alibaba.cloud:spring-cloud-starter-alibaba-sentinel:${alibabaCloud}" implementation "com.alibaba.cloud:spring-cloud-starter-alibaba-sentinel:${alibabaCloud}"

@ -105,11 +105,18 @@ public class VelocityUtils {
*/ */
public static List<String> getTemplateList(String tplCategory) { public static List<String> getTemplateList(String tplCategory) {
List<String> templates = new ArrayList<String>(); List<String> templates = new ArrayList<String>();
templates.add("vm/java/domain.java.vm"); // templates.add("vm/java/domain.java.vm");
templates.add("vm/java/mapper.java.vm"); // templates.add("vm/java/mapper.java.vm");
templates.add("vm/java/service.java.vm"); // templates.add("vm/java/service.java.vm");
templates.add("vm/java/serviceImpl.java.vm"); // templates.add("vm/java/serviceImpl.java.vm");
templates.add("vm/java/controller.java.vm"); // templates.add("vm/java/controller.java.vm");
templates.add("vm/java-plus/domain.java.vm");
templates.add("vm/java-plus/mapper.java.vm");
templates.add("vm/java-plus/service.java.vm");
templates.add("vm/java-plus/serviceImpl.java.vm");
templates.add("vm/java-plus/controller.java.vm");
templates.add("vm/xml/mapper.xml.vm"); templates.add("vm/xml/mapper.xml.vm");
templates.add("vm/sql/sql.vm"); templates.add("vm/sql/sql.vm");
templates.add("vm/js/api.js.vm"); templates.add("vm/js/api.js.vm");
@ -143,7 +150,7 @@ public class VelocityUtils {
if (template.contains("domain.java.vm")) { if (template.contains("domain.java.vm")) {
fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); fileName = StringUtils.format("{}/domain/{}.java", javaPath, className);
} else if (template.contains("mapper.java.vm")) { } else if (template.contains("mapper.java.vm")) {
fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); fileName = StringUtils.format("{}/dao.mysql/{}Mapper.java", javaPath, className);
} else if (template.contains("service.java.vm")) { } else if (template.contains("service.java.vm")) {
fileName = StringUtils.format("{}/service/{}Service.java", javaPath, className); fileName = StringUtils.format("{}/service/{}Service.java", javaPath, className);
} else if (template.contains("serviceImpl.java.vm")) { } else if (template.contains("serviceImpl.java.vm")) {

@ -1,10 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.gen.mapper.GenTableColumnMapper"> <mapper namespace="com.ruoyi.gen.mapper.GenTableColumnMapper">
<resultMap type="GenTableColumn" id="GenTableColumnResult"> <resultMap type="com.ruoyi.gen.domain.GenTableColumn" id="GenTableColumnResult">
<id property="columnId" column="column_id"/> <id property="columnId" column="column_id"/>
<result property="tableId" column="table_id"/> <result property="tableId" column="table_id"/>
<result property="columnName" column="column_name"/> <result property="columnName" column="column_name"/>
@ -33,7 +31,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column
</sql> </sql>
<select id="selectGenTableColumnListByTableId" parameterType="GenTableColumn" resultMap="GenTableColumnResult"> <select id="selectGenTableColumnListByTableId" parameterType="com.ruoyi.gen.domain.GenTableColumn"
resultMap="GenTableColumnResult">
<include refid="selectGenTableColumnVo"/> <include refid="selectGenTableColumnVo"/>
where table_id = #{tableId} where table_id = #{tableId}
order by sort order by sort
@ -45,7 +44,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by ordinal_position order by ordinal_position
</select> </select>
<insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId"> <insert id="insertGenTableColumn" parameterType="com.ruoyi.gen.domain.GenTableColumn" useGeneratedKeys="true"
keyProperty="columnId">
insert into gen_table_column ( insert into gen_table_column (
<if test="tableId != null and tableId != ''">table_id,</if> <if test="tableId != null and tableId != ''">table_id,</if>
<if test="columnName != null and columnName != ''">column_name,</if> <if test="columnName != null and columnName != ''">column_name,</if>
@ -89,7 +89,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
) )
</insert> </insert>
<update id="updateGenTableColumn" parameterType="GenTableColumn"> <update id="updateGenTableColumn" parameterType="com.ruoyi.gen.domain.GenTableColumn">
update gen_table_column update gen_table_column
<set> <set>
column_comment = #{columnComment}, column_comment = #{columnComment},

@ -1,10 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.gen.mapper.GenTableMapper"> <mapper namespace="com.ruoyi.gen.mapper.GenTableMapper">
<resultMap type="GenTable" id="GenTableResult"> <resultMap type="com.ruoyi.gen.domain.GenTable" id="GenTableResult">
<id property="tableId" column="table_id"/> <id property="tableId" column="table_id"/>
<result property="tableName" column="table_name"/> <result property="tableName" column="table_name"/>
<result property="tableComment" column="table_comment"/> <result property="tableComment" column="table_comment"/>
@ -26,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult"/> <collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult"/>
</resultMap> </resultMap>
<resultMap type="GenTableColumn" id="GenTableColumnResult"> <resultMap type="com.ruoyi.gen.domain.GenTableColumn" id="GenTableColumnResult">
<id property="columnId" column="column_id"/> <id property="columnId" column="column_id"/>
<result property="tableId" column="table_id"/> <result property="tableId" column="table_id"/>
<result property="columnName" column="column_name"/> <result property="columnName" column="column_name"/>
@ -55,7 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select table_id, table_name, table_comment, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table select table_id, table_name, table_comment, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table
</sql> </sql>
<select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult"> <select id="selectGenTableList" parameterType="com.ruoyi.gen.domain.GenTable" resultMap="GenTableResult">
<include refid="selectGenTableVo"/> <include refid="selectGenTableVo"/>
<where> <where>
<if test="tableName != null and tableName != ''"> <if test="tableName != null and tableName != ''">
@ -73,7 +71,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where> </where>
</select> </select>
<select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult"> <select id="selectDbTableList" parameterType="com.ruoyi.gen.domain.GenTable" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables select table_name, table_comment, create_time, update_time from information_schema.tables
where table_schema = (select database()) where table_schema = (select database())
AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%' AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%'
@ -117,7 +115,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where t.table_name = #{tableName} order by c.sort where t.table_name = #{tableName} order by c.sort
</select> </select>
<insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId"> <insert id="insertGenTable" parameterType="com.ruoyi.gen.domain.GenTable" useGeneratedKeys="true"
keyProperty="tableId">
insert into gen_table ( insert into gen_table (
<if test="tableName != null">table_name,</if> <if test="tableName != null">table_name,</if>
<if test="tableComment != null and tableComment != ''">table_comment,</if> <if test="tableComment != null and tableComment != ''">table_comment,</if>
@ -151,7 +150,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
) )
</insert> </insert>
<update id="updateGenTable" parameterType="GenTable"> <update id="updateGenTable" parameterType="com.ruoyi.gen.domain.GenTable">
update gen_table update gen_table
<set> <set>
<if test="tableName != null">table_name = #{tableName},</if> <if test="tableName != null">table_name = #{tableName},</if>

@ -0,0 +1,119 @@
package ${packageName}.controller;
import java.util.List;
import java.util.Set;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import ${packageName}.domain.${ClassName};
import ${packageName}.service.${ClassName}Service;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
#if($table.crud)
import com.ruoyi.common.core.web.page.TableDataInfo;
#elseif($table.tree)
#end
/**
* ${functionName}Controller
*
* @author ${author}
* @date ${datetime}
*/
@RestController
@RequestMapping("/${businessName}")
public class ${ClassName}Controller extends BaseController
{
@Autowired
private ${ClassName}Service ${className}Service;
/**
* 查询${functionName}列表
*/
@PreAuthorize(hasPermi = "${permissionPrefix}:list")
@GetMapping("/list")
#if($table.crud)
public TableDataInfo list(${ClassName} ${className})
{
startPage();
List<${ClassName}> list = ${className}Service.list(new QueryWrapper<>(${className}));
return getDataTable(list);
}
#elseif($table.tree)
public AjaxResult list(${ClassName} ${className})
{
List<${ClassName}> list = ${className}Service.list(new QueryWrapper<>(${className}));
return AjaxResult.success(list);
}
#end
/**
* 导出${functionName}列表
*/
@PreAuthorize(hasPermi = "${permissionPrefix}:export")
@Log(title = "${functionName}", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, ${ClassName} ${className}) throws IOException
{
List<${ClassName}> list = ${className}Service.list(new QueryWrapper<>(${className}));
ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
util.exportExcel(response, list, "${businessName}");
}
/**
* 获取${functionName}详细信息
*/
@PreAuthorize(hasPermi = "${permissionPrefix}:query")
@GetMapping(value = "/{${pkColumn.javaField}}")
public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
{
return AjaxResult.success(${className}Service.getById(${pkColumn.javaField}));
}
/**
* 新增${functionName}
*/
@PreAuthorize(hasPermi = "${permissionPrefix}:add")
@Log(title = "${functionName}", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody ${ClassName} ${className})
{
return toAjax(${className}Service.save(${className}) ? 1 : 0);
}
/**
* 修改${functionName}
*/
@PreAuthorize(hasPermi = "${permissionPrefix}:edit")
@Log(title = "${functionName}", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody ${ClassName} ${className})
{
return toAjax(${className}Service.update(new UpdateWrapper(${className})) ? 1 : 0);
}
/**
* 删除${functionName}
*/
@PreAuthorize(hasPermi = "${permissionPrefix}:remove")
@Log(title = "${functionName}", businessType = BusinessType.DELETE)
@DeleteMapping("/{${pkColumn.javaField}s}")
public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s)
{
return toAjax(${className}Service.removeByIds(Set.of(${pkColumn.javaField}s)) ? ${pkColumn.javaField}s.length : 0);
}
}

@ -0,0 +1,58 @@
package ${packageName}.domain;
#foreach ($import in $importList)
import ${import};
#end
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.core.annotation.Excel;
#if($table.crud)
import com.ruoyi.common.core.web.domain.BaseEntity;
#elseif($table.tree)
import com.ruoyi.common.core.web.domain.TreeEntity;
#end
import lombok.Data;
import lombok.Builder;
import com.baomidou.mybatisplus.annotation.TableName;
/**
* ${functionName}对象 ${tableName}
*
* @author ${author}
* @date ${datetime}
*/
#if($table.crud)
#set($Entity="BaseEntity")
#elseif($table.tree)
#set($Entity="TreeEntity")
#end
@Data
@Builder
@TableName("${tableName}")
public class ${ClassName} extends ${Entity}
{
private static final long serialVersionUID = 1L;
#foreach ($column in $columns)
#if(!$table.isSuperColumn($column.javaField))
/** $column.columnComment */
#if($column.list)
#set($parentheseIndex=$column.columnComment.indexOf(""))
#if($parentheseIndex != -1)
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
#else
#set($comment=$column.columnComment)
#end
#if($parentheseIndex != -1)
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
#elseif($column.javaType == 'Date')
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd")
#else
@Excel(name = "${comment}")
#end
#end
private $column.javaType $column.javaField;
#end
#end
}

@ -0,0 +1,14 @@
package ${packageName}.dao.mysql;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import ${packageName}.domain.${ClassName};
/**
* ${functionName}Mapper接口
*
* @author ${author}
* @date ${datetime}
*/
public interface ${ClassName}Mapper extends BaseMapper<${ClassName}> {
}

@ -0,0 +1,13 @@
package ${packageName}.service;
import com.baomidou.mybatisplus.extension.service.IService;
import ${packageName}.domain.${ClassName};
/**
* ${functionName}Service接口
*
* @author ${author}
* @date ${datetime}
*/
public interface ${ClassName}Service extends IService<${ClassName}> {
}

@ -0,0 +1,27 @@
package ${packageName}.service.impl;
import java.util.List;
#foreach ($column in $columns)
#if($column.javaField == 'createTime' || $column.javaField == 'updateTime')
import com.ruoyi.common.core.utils.DateUtils;
#break
#end
#end
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import ${packageName}.dao.mysql.${ClassName}Mapper;
import ${packageName}.domain.${ClassName};
import ${packageName}.service.${ClassName}Service;
/**
* ${functionName}Service业务层处理
*
* @author ${author}
* @date ${datetime}
*/
@Service("${moduleName}${ClassName}Service")
public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}> implements ${ClassName}Service {
}
Loading…
Cancel
Save