⬆️ Upgrading ORM Framework from Mybatis Plus 2.x to Mybatis Plus 3.x

This commit is contained in:
萌萌哒SAKURA酱 committed 2018-11-23 00:58:35 +08:00
1 parent abab6b1859
commit ff47da2767
128 files changed
+1579 -749

No files matched your search

@@ -1,14 +1,31 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package ${package}.${moduleName}.controller;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.plugins.Page;
import com.pig4cloud.pigx.common.core.util.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import ${package}.${moduleName}.entity.${className};
import ${package}.${moduleName}.service.${className}Service;
import com.pig4cloud.pigx.common.core.util.R;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@@ -19,62 +36,65 @@ import java.util.Map;
* @date ${datetime}
*/
@RestController
@RequestMapping("/${pathName}")
@AllArgsConstructor
@RequestMapping("/${pathName}")
public class ${className}Controller {
private final ${className}Service ${classname}Service;
private final ${className}Service ${classname}Service;
/**
* 简单分页查询
* @param page 分页对象
* @param ${classname} ${comments}
* @return
*/
@GetMapping("/page")
public R<IPage<${className}>> get${className}Page(Page<${className}> page, ${className} ${classname}) {
return new R<>(${classname}Service.get${className}Page(page,${classname}));
}
/**
* 列表
* @param params
* @return
*/
@GetMapping("/page")
public R<Page> page(@RequestParam Map<String, Object> params) {
return new R<>(${classname}Service.selectPage(new Query<>(params), new EntityWrapper<>()));
}
/**
* 通过id查询单条记录
* @param ${pk.lowerAttrName}
* @return R
*/
@GetMapping("/{${pk.lowerAttrName}}")
public R<${className}> getById(@PathVariable("${pk.lowerAttrName}") ${pk.attrType} ${pk.lowerAttrName}){
return new R<>(${classname}Service.getById(${pk.lowerAttrName}));
}
/**
* 新增记录
* @param ${classname}
* @return R
*/
@SysLog("新增${comments}")
@PostMapping
public R save(@RequestBody ${className} ${classname}){
return new R<>(${classname}Service.save(${classname}));
}
/**
* 信息
* @param ${pk.lowerAttrName}
* @return R
*/
@GetMapping("/{${pk.lowerAttrName}}")
public R get${className}ById(@PathVariable("${pk.lowerAttrName}") ${pk.attrType} ${pk.lowerAttrName}){
return new R<>(${classname}Service.selectById(${pk.lowerAttrName}));
}
/**
* 修改记录
* @param ${classname}
* @return R
*/
@SysLog("修改${comments}")
@PutMapping
public R update(@RequestBody ${className} ${classname}){
return new R<>(${classname}Service.updateById(${classname}));
}
/**
* 保存
* @param ${classname}
* @return R
*/
@PostMapping
public R save${className}(@RequestBody ${className} ${classname}){
return new R<>(${classname}Service.insert(${classname}));
}
/**
* 修改
* @param ${classname}
* @return R
*/
@PutMapping
public R update${className}(@RequestBody ${className} ${classname}){
${classname}Service.updateById(${classname});
return new R<>(Boolean.TRUE);
}
/**
* 删除
* @param ${pk.lowerAttrName}
* @return R
*/
@DeleteMapping("/{${pk.lowerAttrName}}")
public R delete${className}ById(@PathVariable ${pk.attrType} ${pk.lowerAttrName}){
return new R<>(${classname}Service.deleteById(${pk.lowerAttrName}));
}
/**
* 通过id删除一条记录
* @param ${pk.lowerAttrName}
* @return R
*/
@SysLog("删除${comments}")
@DeleteMapping("/{${pk.lowerAttrName}}")
public R removeById(@PathVariable ${pk.attrType} ${pk.lowerAttrName}){
return new R<>(${classname}Service.removeById(${pk.lowerAttrName}));
}
}
@@ -1,12 +1,27 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package ${package}.${moduleName}.entity;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;
import lombok.EqualsAndHashCode;
#if(${hasBigDecimal})
#if(${hasBigDecimal})
import java.math.BigDecimal;
#end
import java.io.Serializable;
@@ -19,26 +34,19 @@ import java.time.LocalDateTime;
* @date ${datetime}
*/
@Data
@TableName("${tableName}")
@EqualsAndHashCode(callSuper = true)
@TableName("${tableName}")
public class ${className} extends Model<${className}> {
private static final long serialVersionUID = 1L;
#foreach ($column in $columns)
/**
* $column.comments
*/
#if($column.columnName == $pk.columnName)
@TableId(type = IdType.AUTO)
#end
private $column.attrType $column.lowerAttrName;
#end
private static final long serialVersionUID = 1L;
#foreach ($column in $columns)
/**
* 主键值
* $column.comments
*/
@Override
protected Serializable pkVal() {
return this.$pk.lowerAttrName;
}
#if($column.columnName == $pk.columnName)
@TableId
#end
private $column.attrType $column.lowerAttrName;
#end
}
@@ -1,8 +1,26 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package ${package}.${moduleName}.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${package}.${moduleName}.entity.${className};
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* ${comments}
@@ -10,7 +28,13 @@ import org.apache.ibatis.annotations.Mapper;
* @author ${author}
* @date ${datetime}
*/
@Mapper
public interface ${className}Mapper extends BaseMapper<${className}> {
/**
* ${comments}简单分页查询
* @param ${classname} ${comments}
* @return
*/
IPage<${className}> get${className}Page(Page page, @Param("${classname}") ${className} ${classname});
}
@@ -1,14 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~
~ Copyright (c) 2018-2025, lengleng All rights reserved.
~
~ Redistribution and use in source and binary forms, with or without
~ modification, are permitted provided that the following conditions are met:
~
~ Redistributions of source code must retain the above copyright notice,
~ this list of conditions and the following disclaimer.
~ Redistributions in binary form must reproduce the above copyright
~ notice, this list of conditions and the following disclaimer in the
~ documentation and/or other materials provided with the distribution.
~ Neither the name of the pig4cloud.com developer nor the names of its
~ contributors may be used to endorse or promote products derived from
~ this software without specific prior written permission.
~ Author: lengleng (wangiegie@gmail.com)
~
-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${package}.${moduleName}.mapper.${className}Mapper">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="${package}.${moduleName}.entity.${className}" id="${classname}Map">
#foreach($column in $columns)
<resultMap id="${classname}Map" type="${package}.${moduleName}.entity.${className}">
#foreach($column in $columns)
#if($column.lowerAttrName==$pk.lowerAttrName)
<id property="${pk.lowerAttrName}" column="${pk.columnName}"/>
#else
<result property="${column.lowerAttrName}" column="${column.columnName}"/>
#end
</resultMap>
#end
#end
</resultMap>
<!--${classname}简单分页查询-->
<select id="get${className}Page" resultMap="${classname}Map">
SELECT
#foreach($column in $columns)
#if($foreach.count==$!{columns.size()})
${column.columnName}
#else
${column.columnName},
#end
#end
FROM ${tableName}
<where>
#foreach($column in $columns)
<if test="${classname}.$column.lowerAttrName != null and ${classname}.${column.lowerAttrName}.trim() != ''">
AND ${column.columnName} = #{${classname}.$column.lowerAttrName}
</if>
#end
</where>
</select>
</mapper>
@@ -1,6 +1,24 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package ${package}.${moduleName}.service;
import com.baomidou.mybatisplus.service.IService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import ${package}.${moduleName}.entity.${className};
/**
@@ -10,5 +28,13 @@ import ${package}.${moduleName}.entity.${className};
* @date ${datetime}
*/
public interface ${className}Service extends IService<${className}> {
}
/**
* ${comments}简单分页查询
* @param ${classname} ${comments}
* @return
*/
IPage<${className}> get${className}Page(Page<${className}> page, ${className} ${classname});
}
@@ -1,17 +1,45 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package ${package}.${moduleName}.service.impl;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import ${package}.${moduleName}.mapper.${className}Mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import ${package}.${moduleName}.entity.${className};
import ${package}.${moduleName}.service.${className}Service;
import org.springframework.stereotype.Service;
/**
* ${comments}
*
* @author ${author}
* @date ${datetime}
*/
@Service("${classname}Service")
public class ${className}ServiceImpl extends ServiceImpl<${className}Mapper, ${className}> implements ${className}Service {
/**
* ${comments}简单分页查询
* @param ${classname} ${comments}
* @return
*/
@Override
public IPage<${className}> get${className}Page(Page<${className}> page, ${className} ${classname}){
return baseMapper.get${className}Page(page,${classname});
}
}
@@ -18,6 +18,7 @@
export const tableOption = {
'border': true,
'index': true,
'indexLabel': '序号',
'stripe': true,
'menuAlign': "center",
'align': "center",
@@ -1,20 +1,3 @@
<!--
- Copyright (c) 2018-2025, lengleng All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- Neither the name of the pig4cloud.com developer nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
- Author: lengleng (wangiegie@gmail.com)
-->
<template>
<div class="app-container pull-auto">
<basic-container>
@@ -23,8 +6,9 @@
:data="tableData"
:table-loading="tableLoading"
:option="tableOption"
@on-load="getList"
@current-change="currentChange"
@refresh-change="refreshChange"
@size-change="sizeChange"
@row-update="handleUpdate"
@row-save="handleSave"
@row-del="rowDel">
@@ -69,28 +53,40 @@
currentPage: 1, // 当前页数
pageSize: 20 // 每页显示多少条
},
listQuery: {
current: 1,
size: 20
},
tableLoading: false,
tableOption: tableOption
}
},
created() {
this.getList()
},
mounted: function() { },
computed: {
...mapGetters(['permissions'])
},
methods: {
getList(page, params) {
getList() {
this.tableLoading = true
fetchList(Object.assign({
page: page.currentPage,
limit: page.pageSize
}, params)).then(response => {
this.tableData = response.data.records
this.page.total = response.data.total
fetchList(this.listQuery).then(response => {
this.tableData = response.data.data.records
this.page.total = response.data.data.total
this.tableLoading = false
})
},
currentChange(val) {
this.page.current = val
this.listQuery.current = val
this.getList()
},
sizeChange(val) {
this.page.size = val
this.listQuery.size = val
this.getList()
},
/**
* @title 打开新增窗口
* @detail 调用crud的handleadd方法即可
@@ -107,7 +103,7 @@
},
rowDel: function(row, index) {
var _this = this
this.$confirm('是否确认删除ID为' + row.$pk.lowerAttrName, '提示', {
this.$confirm('是否确认删除ID为' + row.$pk.lowerAttrName + '的记录', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
@@ -136,11 +132,11 @@
handleUpdate: function(row, index, done) {
putObj(row).then(data => {
this.tableData.splice(index, 1, Object.assign({}, row))
this.$message({
showClose: true,
message: '修改成功',
type: 'success'
})
this.$message({
showClose: true,
message: '修改成功',
type: 'success'
})
done()
this.getList(this.page)
})
@@ -154,20 +150,20 @@
handleSave: function(row, done) {
addObj(row).then(data => {
this.tableData.push(Object.assign({}, row))
this.$message({
showClose: true,
message: '添加成功',
type: 'success'
})
done()
this.getList(this.page)
this.$message({
showClose: true,
message: '添加成功',
type: 'success'
})
done()
this.getList(this.page)
})
},
/**
* 刷新回调
*/
refreshChange() {
this.getList(this.page)
this.getList()
}
}
}
@@ -1,13 +1,13 @@
-- 该脚本不要执行,请完善 ID 对应关系,注意层级关系 !!!!
-- 菜单SQL
insert into `sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`, `tenant_id`)
values ( '父菜单ID', 'views/${moduleName}/${pathName}/index', '', '0', '${pathName}', 'icon-bangzhushouji', '菜单ID', '0', '2018-01-20 13:17:19', '8', '2018-07-29 13:38:19', '${comments}管理','1');
insert into `pigx`.`sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
values ( '父菜单ID', 'views/${moduleName}/${pathName}/index', '', '0', '${pathName}', 'icon-bangzhushouji', '菜单ID', '0', '2018-01-20 13:17:19', '8', '2018-07-29 13:38:19', '${comments}管理');
-- 菜单对应按钮SQL
insert into `sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`, `tenant_id`)
values ( '菜单ID', null, '${moduleName}_${pathName}_add', '1', null, '1', '子按钮ID1', '0', '2018-05-15 21:35:18', '0', '2018-07-29 13:38:59', '${comments}新增','1');
insert into `sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`, `tenant_id`)
values ( '菜单ID', null, '${moduleName}_${pathName}_edit', '1', null, '1', '子按钮ID2', '0', '2018-05-15 21:35:18', '1', '2018-07-29 13:38:59', '${comments}修改','1');
insert into `sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`, `tenant_id`)
values ( '菜单ID', null, '${moduleName}_${pathName}_del', '1', null, '1', '子按钮ID3', '0', '2018-05-15 21:35:18', '2', '2018-07-29 13:38:59', '${comments}删除','1');
insert into `pigx`.`sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
values ( '菜单ID', null, '${moduleName}_${pathName}_add', '1', null, '1', '子按钮ID1', '0', '2018-05-15 21:35:18', '0', '2018-07-29 13:38:59', '${comments}新增');
insert into `pigx`.`sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
values ( '菜单ID', null, '${moduleName}_${pathName}_edit', '1', null, '1', '子按钮ID2', '0', '2018-05-15 21:35:18', '1', '2018-07-29 13:38:59', '${comments}修改');
insert into `pigx`.`sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
values ( '菜单ID', null, '${moduleName}_${pathName}_del', '1', null, '1', '子按钮ID3', '0', '2018-05-15 21:35:18', '2', '2018-07-29 13:38:59', '${comments}删除');