♻️ Refactoring code. mybatis plus 3.x refactor
This commit is contained in:
1 parent
ff47da2767
commit
c981e6137d
77 files changed
+463
-1340
No files matched your search
@@ -49,8 +49,8 @@ public class ${className}Controller {
|
||||
* @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}));
|
||||
public R get${className}Page(Page page, ${className} ${classname}) {
|
||||
return new R<>(${classname}Service.page(page,Wrappers.query(${classname})));
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class ${className}Controller {
|
||||
* @return R
|
||||
*/
|
||||
@GetMapping("/{${pk.lowerAttrName}}")
|
||||
public R<${className}> getById(@PathVariable("${pk.lowerAttrName}") ${pk.attrType} ${pk.lowerAttrName}){
|
||||
public R getById(@PathVariable("${pk.lowerAttrName}") ${pk.attrType} ${pk.lowerAttrName}){
|
||||
return new R<>(${classname}Service.getById(${pk.lowerAttrName}));
|
||||
}
|
||||
|
||||
|
||||
@@ -29,12 +29,5 @@ import org.apache.ibatis.annotations.Param;
|
||||
* @date ${datetime}
|
||||
*/
|
||||
public interface ${className}Mapper extends BaseMapper<${className}> {
|
||||
/**
|
||||
* ${comments}简单分页查询
|
||||
* @param ${classname} ${comments}
|
||||
* @return
|
||||
*/
|
||||
IPage<${className}> get${className}Page(Page page, @Param("${classname}") ${className} ${classname});
|
||||
|
||||
|
||||
}
|
||||
@@ -32,27 +32,4 @@
|
||||
#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>
|
||||
@@ -29,12 +29,4 @@ import ${package}.${moduleName}.entity.${className};
|
||||
*/
|
||||
public interface ${className}Service extends IService<${className}> {
|
||||
|
||||
/**
|
||||
* ${comments}简单分页查询
|
||||
* @param ${classname} ${comments}
|
||||
* @return
|
||||
*/
|
||||
IPage<${className}> get${className}Page(Page<${className}> page, ${className} ${classname});
|
||||
|
||||
|
||||
}
|
||||
@@ -32,14 +32,4 @@ import org.springframework.stereotype.Service;
|
||||
@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});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,20 @@
|
||||
<!--
|
||||
- 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>
|
||||
@@ -6,9 +23,8 @@
|
||||
:data="tableData"
|
||||
:table-loading="tableLoading"
|
||||
:option="tableOption"
|
||||
@current-change="currentChange"
|
||||
@on-load="getList"
|
||||
@refresh-change="refreshChange"
|
||||
@size-change="sizeChange"
|
||||
@row-update="handleUpdate"
|
||||
@row-save="handleSave"
|
||||
@row-del="rowDel">
|
||||
@@ -53,122 +69,109 @@
|
||||
currentPage: 1, // 当前页数
|
||||
pageSize: 20 // 每页显示多少条
|
||||
},
|
||||
listQuery: {
|
||||
current: 1,
|
||||
size: 20
|
||||
},
|
||||
tableLoading: false,
|
||||
tableOption: tableOption
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getList()
|
||||
},
|
||||
mounted: function() { },
|
||||
computed: {
|
||||
...mapGetters(['permissions'])
|
||||
},
|
||||
methods: {
|
||||
getList() {
|
||||
this.tableLoading = true
|
||||
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方法即可
|
||||
*
|
||||
**/
|
||||
handleAdd: function() {
|
||||
this.$refs.crud.rowAdd()
|
||||
},
|
||||
handleEdit(row, index) {
|
||||
this.$refs.crud.rowEdit(row, index)
|
||||
},
|
||||
handleDel(row, index) {
|
||||
this.$refs.crud.rowDel(row, index)
|
||||
},
|
||||
rowDel: function(row, index) {
|
||||
var _this = this
|
||||
this.$confirm('是否确认删除ID为' + row.$pk.lowerAttrName + '的记录', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
.then(function() {
|
||||
return delObj(row.$pk.lowerAttrName)
|
||||
methods: {
|
||||
getList(page, params) {
|
||||
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
|
||||
this.tableLoading = false
|
||||
})
|
||||
.then(data => {
|
||||
_this.tableData.splice(index, 1)
|
||||
_this.$message({
|
||||
showClose: true,
|
||||
message: '删除成功',
|
||||
type: 'success'
|
||||
},
|
||||
/**
|
||||
* @title 打开新增窗口
|
||||
* @detail 调用crud的handleadd方法即可
|
||||
*
|
||||
**/
|
||||
handleAdd: function() {
|
||||
this.$refs.crud.rowAdd()
|
||||
},
|
||||
handleEdit(row, index) {
|
||||
this.$refs.crud.rowEdit(row, index)
|
||||
},
|
||||
handleDel(row, index) {
|
||||
this.$refs.crud.rowDel(row, index)
|
||||
},
|
||||
rowDel: function(row, index) {
|
||||
var _this = this
|
||||
this.$confirm('是否确认删除ID为' + row.$pk.lowerAttrName, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
.then(function() {
|
||||
return delObj(row.$pk.lowerAttrName)
|
||||
})
|
||||
.then(data => {
|
||||
_this.tableData.splice(index, 1)
|
||||
_this.$message({
|
||||
showClose: true,
|
||||
message: '删除成功',
|
||||
type: 'success'
|
||||
})
|
||||
this.getList(this.page)
|
||||
})
|
||||
.catch(function(err) { })
|
||||
},
|
||||
/**
|
||||
* @title 数据更新
|
||||
* @param row 为当前的数据
|
||||
* @param index 为当前更新数据的行数
|
||||
* @param done 为表单关闭函数
|
||||
*
|
||||
**/
|
||||
handleUpdate: function(row, index, done) {
|
||||
putObj(row).then(data => {
|
||||
this.tableData.splice(index, 1, Object.assign({}, row))
|
||||
this.$message({
|
||||
showClose: true,
|
||||
message: '修改成功',
|
||||
type: 'success'
|
||||
})
|
||||
done()
|
||||
this.getList(this.page)
|
||||
})
|
||||
},
|
||||
/**
|
||||
* @title 数据添加
|
||||
* @param row 为当前的数据
|
||||
* @param done 为表单关闭函数
|
||||
*
|
||||
**/
|
||||
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)
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 刷新回调
|
||||
*/
|
||||
refreshChange() {
|
||||
this.getList(this.page)
|
||||
})
|
||||
.catch(function(err) { })
|
||||
},
|
||||
/**
|
||||
* @title 数据更新
|
||||
* @param row 为当前的数据
|
||||
* @param index 为当前更新数据的行数
|
||||
* @param done 为表单关闭函数
|
||||
*
|
||||
**/
|
||||
handleUpdate: function(row, index, done) {
|
||||
putObj(row).then(data => {
|
||||
this.tableData.splice(index, 1, Object.assign({}, row))
|
||||
this.$message({
|
||||
showClose: true,
|
||||
message: '修改成功',
|
||||
type: 'success'
|
||||
})
|
||||
done()
|
||||
this.getList(this.page)
|
||||
})
|
||||
},
|
||||
/**
|
||||
* @title 数据添加
|
||||
* @param row 为当前的数据
|
||||
* @param done 为表单关闭函数
|
||||
*
|
||||
**/
|
||||
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)
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 刷新回调
|
||||
*/
|
||||
refreshChange() {
|
||||
this.getList()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
|
||||
Reference in new issue
Block a user