EasyCode 模板

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
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 201,681评论 5 474
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,710评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 148,623评论 0 334
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,202评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,232评论 5 363
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,368评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,795评论 3 393
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,461评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,647评论 1 295
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,476评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,525评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,226评论 3 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,785评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,857评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,090评论 1 258
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,647评论 2 348
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,215评论 2 341

推荐阅读更多精彩内容