• blade普通字典关联


    bladex代码生成有点low,用过jeecg的都知道。

    bladex 有个notice服务,我是参照那个来改的。

    前端:

    第一步:

    粉色代码是添加的代码,生成的前端代码里面是没有的

    这里 isDelete是你类(Test)对象的字典字段。isDeleteName是对应的VO(TestVO)的字段。修改控制的时候就知道了,在下面。

          <el-button type="danger"
                       size="small"
                       icon="el-icon-delete"
                       plain
                       v-if="permission.test_delete"
                       @click="handleDelete">删 除
            </el-button>
          </template>
    
          <template slot-scope="{row}"
                    slot="isDeleted">
            <el-tag>{{row.isDeletedName}}</el-tag>
          </template>
    
        </avue-crud>
      </basic-container>

    第二步:

    粉色代码是添加的代码,生成的前端代码里面是没有的。

    <script>
      import AvueUeditor from 'avue-plugin-ueditor';
      import {getList, getDetail, add, update, remove} from "@/api/subway/test";
      import {mapGetters} from "vuex";

    第三步:

    yes_no是对应的字典code,isDeleted是实体(Test)字段

      {
                  label: "删除标识",
                  type: "select",
                  dicUrl: "/api/blade-system/dict/dictionary?code=yes_no",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  dataType: "number",
                  slot: true,
                  prop: "isDeleted",
                  search: true,
                  rules: [{
                    required: true,
                    message: "请输入删除标识",
                    trigger: "blur"
                  }]
                }

    后端代码:

    第一步:加包加类。(代码生成没有)

     类如下,注意粉色地方,没有什么好说。

    package org.springblade.subway.wrapper;
    
    import org.springblade.core.mp.support.BaseEntityWrapper;
    import org.springblade.core.tool.utils.BeanUtil;
    
    import org.springblade.subway.entity.Test;
    import org.springblade.subway.vo.TestVO;
    import org.springblade.system.cache.DictCache;
    
    import java.util.Objects;
    
    /**
     * Notice包装类,返回视图层所需的字段
     *
     * @author Chill
     */
    public class TestWrapper extends BaseEntityWrapper<Test, TestVO> {
    
        public static TestWrapper build() {
            return new TestWrapper();
        }
    
        @Override
        public TestVO entityVO(Test notice) {
            TestVO noticeVO = Objects.requireNonNull(BeanUtil.copy(notice, TestVO.class));
            String dictValue = DictCache.getValue("yes_no", noticeVO.getIsDeleted());
            noticeVO.setIsDeletedName(dictValue);
            return noticeVO;
        }
    
    }

    TestVO加入如下字段,和vue文件中对应

    @Data
    @EqualsAndHashCode(callSuper = true)
    @ApiModel(value = "TestVO对象", description = "地铁测试")
    public class TestVO extends Test {
        private static final long serialVersionUID = 1L;
    
        @ApiModelProperty(value = "通知类型名")
        private String isDeletedName;
    
    }

    控制器:

    第一个粉色部分:生成的是Test test类,改成了map

    第二个粉色部分,是上面的添加的那个类

    /**
         * 分页 地铁测试
         */
        @GetMapping("/list")
        @ApiOperationSupport(order = 2)
        @ApiOperation(value = "分页", notes = "传入test")
        public R<IPage<TestVO>> list(@ApiIgnore @RequestParam Map<String, Object>  test, Query query) {
            //IPage<Test> pages = testService.page(Condition.getPage(query), Condition.getQueryWrapper(test));
            //return R.data(pages);
    
    
            IPage<Test> pages = testService.page(Condition.getPage(query), Condition.getQueryWrapper(test, Test.class));
            R<IPage<TestVO>>  result=R.data(TestWrapper.build().pageVO(pages));
            return result;
        }

     参考 https://www.cnblogs.com/edrp/p/11910081.html  关联类。

  • 相关阅读:
    曾今的代码系列——获取当天最大流水号存储过程
    曾今的代码系列——生产者消费者模式
    利用Microsoft.VisualBasic中TextFieldParser解析器把CSV格式倒入数据库
    曾今的代码系列——自己的分页控件+存储过程实现分页
    ASP.NET那点不为人知的事(四)
    SharePoint下用C#代码上传文档至文档库的子文件夹中
    Entity Framework 4 in Action读书笔记——第四章:使用LINQ to Entities查询:使用函数
    Entity Framework 4 in Action读书笔记——第四章:使用LINQ to Entities查询:预先加载和延迟加载
    这几天Colorbox让我寝食难安
    使用ASP.NET MVC3+EF+Jquery制作文字直播系统(四)——完成篇
  • 原文地址:https://www.cnblogs.com/longsanshi/p/12661255.html
Copyright © 2020-2023  润新知