controller
##导入宏定义
$!define
##设置表后缀(宏定义)
#setTableSuffix("Controller")
##保存文件(宏定义)
#save("/controller", "Controller.java")
##包路径(宏定义)
#setPackageSuffix("controller")
##定义服务名
#set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service"))
##定义实体对象名
#set($entityName = $!tool.firstLowerCase($!tableInfo.name))
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name}Entity;
import $!{tableInfo.savePackageName}.service.I$!{tableInfo.name}Service;
import com.sf.ibu.mansri.common.dto.Result;
import com.sf.ibu.mansri.common.query.QueryGenerator;
import com.sf.ibu.mansri.common.utils.I18nUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
##表注释(宏定义)
#tableComment("表控制层")
@Slf4j
@RestController
@RequestMapping("$!tool.firstLowerCase($!tableInfo.name)")
public class $!{tableName}{
/**
* 服务对象
*/
@Autowired
private I$!{tableInfo.name}Service $!{serviceName};
/**
* 分页查询所有数据
* @param mansriDownloadRecord 查询实体
* @param pageNum 当前页码
* @param pageSize 分页大小
* @param req 请求
* @return 查询实体
*/
@GetMapping("/list")
public Result<IPage<$!{tableInfo.name}Entity>> list($!{tableInfo.name}Entity $!entityName,
@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest req) {
QueryWrapper<$!{tableInfo.name}Entity> queryWrapper = QueryGenerator.initQueryWrapper($!entityName, req.getParameterMap());
Page<$!{tableInfo.name}Entity> page = new Page<>(pageNum, pageSize);
IPage<$!{tableInfo.name}Entity> pageList = $!{serviceName}.page(page, queryWrapper);
return Result.ok(pageList);
}
/**
* 新增数据
*
* @param $!entityName 实体对象
* @return 新增结果
*/
@PostMapping("/add")
public Result<String> insert(@RequestBody $!{tableInfo.name}Entity $!entityName) {
$!{serviceName}.save($!entityName);
return Result.ok(I18nUtil.getMessage("add_success"));
}
/**
* 修改数据
*
* @param $!entityName 实体对象
* @return 修改结果
*/
@PutMapping("/edit")
public Result<String> update(@RequestBody $!{tableInfo.name}Entity $!entityName) {
$!{serviceName}.updateById($!entityName);
return Result.ok(I18nUtil.getMessage("update_success"));
}
/**
* 删除数据
*
* @param id 主键结合
* @return 删除结果
*/
@DeleteMapping(value = "/deleteBatch")
public Result<String> delete(@RequestParam(name = "id") String id) {
$!{serviceName}.removeByIds(Arrays.asList(id.split(",")));
return Result.ok(I18nUtil.getMessage("batch_delete_success"));
}
/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping("/queryById")
public Result<$!{tableInfo.name}Entity> queryById(@RequestParam(name = "id") String id) {
return Result.ok($!{serviceName}.getById(id));
}
}
service
##导入宏定义
$!define
##设置表后缀(宏定义)
#setTableSuffix("Service")
##保存文件(宏定义)
#save("/service", "Service.java", "I")
##包路径(宏定义)
#setPackageSuffix("service")
import com.baomidou.mybatisplus.extension.service.IService;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name}Entity;
##表注释(宏定义)
#tableComment("表服务接口")
public interface I$!{tableName} extends IService<$!{tableInfo.name}Entity> {
}
serviceImpl
##导入宏定义
$!define
##设置表后缀(宏定义)
#setTableSuffix("ServiceImpl")
##保存文件(宏定义)
#save("/service/impl", "ServiceImpl.java")
##包路径(宏定义)
#setPackageSuffix("service.impl")
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name}Entity;
import $!{tableInfo.savePackageName}.service.I$!{tableInfo.name}Service;
import org.springframework.stereotype.Service;
##表注释(宏定义)
#tableComment("表服务实现类")
@Service
public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Mapper, $!{tableInfo.name}Entity> implements I$!{tableInfo.name}Service {
}
mapper
##导入宏定义
$!define
##设置表后缀(宏定义)
#setTableSuffix("Mapper")
##保存文件(宏定义)
#save("/mapper", "Mapper.java")
##包路径(宏定义)
#setPackageSuffix("mapper")
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name}Entity;
##表注释(宏定义)
#tableComment("表数据库访问层")
public interface $!{tableName} extends BaseMapper<$!{tableInfo.name}Entity> {
}
Mapper.xml
##引入mybatis支持
$!mybatisSupport
##导入宏定义
$!define
##设置保存名称与保存位置
##保存文件(宏定义)
#save("/mapper/xml", "Mapper.xml")
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="$!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper">
</mapper>
entity
##导入宏定义
$!define
##设置表后缀(宏定义)
#setTableSuffix("Entity")
##保存文件(宏定义)
#save("/entity", "Entity.java")
##包路径(宏定义)
#setPackageSuffix("entity")
##自动导入包(全局变量)
$!autoImport
import com.baomidou.mybatisplus.annotation.TableName;
import com.sf.ibu.mansri.common.entity.BaseEntity;
import lombok.Data;
##表注释(宏定义)
#tableComment("表实体类")
@TableName("$!tableInfo.obj.name")
@Data
public class $!{tableInfo.name}Entity extends BaseEntity {
#foreach($column in $tableInfo.fullColumn)
/**
* #if(${column.comment}) ${column.comment}
#end
*/
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
}
###foreach($column in $tableInfo.fullColumn)
###getSetMethod($column)
###end
##
###foreach($column in $tableInfo.pkColumn)
## /**
## * 获取主键值
## *
## * @return 主键值
## */
## @Override
## protected Serializable pkVal() {
## return this.$!column.name;
## }
## #break
###end
##}
translate
##引入宏定义
$!define
$!callback.setFileName($tool.append($!{tableInfo.name}, "message_zh_CN.properties"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/messages"))
#foreach($column in $tableInfo.fullColumn)
$!tool.firstLowerCase($!{tableInfo.name}).$!{column.name} = ${column.comment}
#end
vue
/* eslint-disable */
<template>
<SearchForm :formData="filterForm" @collapseToggle="collapseToggle" @onSubmit="handleFilter" />
<div class="component-control">
<el-button type="primary" @click="handleAdd">{{ $t("button.add") }}</el-button>
<el-button type="danger" @click="handleDelete()">{{ $t("button.deleteInBatches") }}</el-button>
</div>
<div class="component-content">
<el-table
:max-height="tableMaxHeight"
:border="true"
:resizable="true"
:data="tableData"
ref="multipleTable"
:row-key="(row) => row.id"
@selection-change="selectionChange"
>
<el-table-column fixed="left" type="selection" width="50px" reserve-selection></el-table-column>
<el-table-column
v-for="item in tableColumn"
:key="item.prop"
:label="item.label"
:width="item.width"
:min-width="item.label.length * 13 + 20"
:prop="item.prop"
:formatter="item.formatter"
>
</el-table-column>
<el-table-column fixed="right" width="160" :label="$t('common.action')">
<template #header>
<span>{{ $t("common.action") }}</span>
<field-setting :columns="columns" @change="setTableColumnByField" />
</template>
<template #default="scope">
<el-button type="text" @click="handleEdit(scope)">{{ $t("button.edit") }}</el-button>
<el-button type="text" @click="handleView(scope)">{{ $t("button.view") }}</el-button>
<el-button type="text" @click="handleDelete(scope)">{{ $t("button.delete") }}</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
v-model:current-page="pagination.pageNum"
:page-sizes="[20, 50, 100, 200]"
v-model:page-size="pagination.pageSize"
layout="prev, pager, next, jumper, sizes, total"
:total="pagination.total"
>
</el-pagination>
</div>
<el-dialog
:close-on-click-modal="false"
width="540px"
:title="dialogTitle"
v-model="dialogVisible"
:destroy-on-close="true"
>
<SearchForm :formData="editForm" @onSubmit="editFormSubmit" />
</el-dialog>
</template>
<script lang="ts">
import api from "@/api";
import { defineComponent, onMounted, reactive, ref } from "vue";
import SearchForm from "@/components/searchform/index.vue";
import FieldSetting from "@/components/fieldSetting/index.vue";
import initNormalList from "@/hooks/normalList";
export default defineComponent({
name: "$!tool.firstLowerCase($!tableInfo.name)",
components: { SearchForm, FieldSetting },
setup() {
const { $t } = $i18n;
const $mt = (name: string) => $t(`backManage.$!tool.firstLowerCase($!tableInfo.name).${name}`);
const {
pagination,
handleSizeChange,
handleCurrentChange,
filterFormData,
handleEditSubmit,
tableData,
getTableData,
filterFormSubmit,
selectionChange,
editForm,
handleDelete,
http,
multipleTable,
collapseToggle,
tableMaxHeight,
} = initNormalList();
const filterForm = reactive({});
const dialogVisible = ref(false);
const dialogTitle = ref("新增");
Object.assign(http, {
query: api.$!{tool.firstLowerCase($!tableInfo.name)}.list,
create: api.$!{tool.firstLowerCase($!tableInfo.name)}.save,
update: api.$!{tool.firstLowerCase($!tableInfo.name)}.edit,
delete: api.$!{tool.firstLowerCase($!tableInfo.name)}.deleteBatch,
});
Object.assign(filterForm, {
type: "filter",
columnList: [
#foreach($column in $tableInfo.fullColumn)
#if($column.name != "createBy" && $column.name != "createTime" && $column.name != "updateBy" && $column.name != "updateTime" && $column.name != "id" )
{
key: "$!{column.name}",
label: $mt("$!{column.name}"),
},
#end
#end
],
});
// 初始化表格
const setColumns = () => [
#foreach($column in $tableInfo.fullColumn)
#if($column.name != "createBy" && $column.name != "createTime" && $column.name != "updateBy" && $column.name != "updateTime" && $column.name != "id" )
{
prop: "$!{column.name}",
label: $mt("$!{column.name}"),
},
#end
#end
];
const columns = setColumns();
const tableColumn = ref([]);
// 设置表格表头字段
const setTableColumnByField = (fields: Array<string>) => {
(tableColumn.value as typeof columns) = columns.filter((item) => fields.includes(item.label));
};
// 设置弹窗 内容
Object.assign(editForm, {
initialForm: undefined,
span: 24,
columnList: [
#foreach($column in $tableInfo.fullColumn)
#if($column.name != "createBy" && $column.name != "createTime" && $column.name != "updateBy" && $column.name != "updateTime" && $column.name != "id" )
{
key: "$!{column.name}",
label: $mt("$!{column.name}"),
},
#end
#end
],
});
// 设置弹窗类型 添加 编辑 查看
const setEditForm = (val?: any, type?: string) => {
editForm.initialForm = val;
editForm.disabled = type === "view";
if (val) {
editForm.columnList = editForm.columnList.map((item) => {
return {
...item,
disabled: type === "view",
};
});
} else {
editForm.columnList = editForm.columnList.map((item) => ({
...item,
disabled: false,
}));
}
};
// 筛选
const handleFilter = (val: object) => {
filterFormSubmit(val);
};
// 添加
const handleAdd = () => {
dialogTitle.value = $t("button.add");
dialogVisible.value = true;
setEditForm();
};
// 修改
const handleEdit = (scope: any) => {
const { row } = scope;
dialogTitle.value = $t("button.edit");
dialogVisible.value = true;
setEditForm(row, "edit");
};
// 查看
const handleView = (scope: any) => {
const { row } = scope;
dialogTitle.value = $t("button.view");
dialogVisible.value = true;
setEditForm(row, "view");
};
// 查询 前置方法
const filterFormatter = (val?: any) => {
const form = val || filterFormData;
return {
...form,
};
};
// 添加或者保存提交方法
const editFormSubmit = async (form: any) => {
const params = {
...form,
};
let type = "create";
if (editForm.initialForm) {
const { id } = editForm.initialForm as any;
params.id = id;
type = "update";
}
await handleEditSubmit(params, type);
dialogVisible.value = false;
getTableData(filterFormatter());
};
onMounted(async () => {
getTableData(filterFormatter());
});
return {
$t,
$mt,
handleView,
dialogTitle,
filterForm,
tableData,
columns,
tableColumn,
getTableData,
selectionChange,
handleAdd,
handleEdit,
handleDelete,
pagination,
handleSizeChange,
handleCurrentChange,
dialogVisible,
editForm,
editFormSubmit,
multipleTable,
handleFilter,
setTableColumnByField,
collapseToggle,
tableMaxHeight,
};
},
});
</script>
<style lang="scss" scoped>
</style>
translatejs
##引入宏定义
$!define
#foreach($column in $tableInfo.fullColumn)
#if($column.name != "createBy" && $column.name != "createTime" && $column.name != "updateBy" && $column.name != "updateTime" && $column.name != "id")
$!{column.name}:"${column.comment}",
#end
#end