三级下拉选

1、建表


image.png

一级下拉选没有father_id,二级下拉选的father_id是一级下拉选的id,三级下拉选的father_id是二级下拉选的id,以此类推。
2、SQL

<!-- 报修工单 1级下拉选-->
      <select id="findFirst1" resultMap="BaseResultMap">
          SELECT
                id,
                "name",
                father_id
          FROM
                out_dictionary
          WHERE
              father_id IS NULL
    </select>
    <!-- 报修工单 2级下拉选-->
    <select id="findSecond2" resultMap="BaseResultMap">
        SELECT  
            id,
            "name" ,
            "type",
            father_id  
        FROM  
            out_dictionary  
        WHERE  
            father_id =#{fatherId}
    </select>
    <!-- 报修工单 3级下拉选-->
    <select id="findThird3" resultMap="BaseResultMap">
        SELECT  
            id,
            "name",
            "type",
            father_id  
        FROM  
            out_dictionary  
        WHERE  
            father_id =#{fatherId}
    </select>

3、Dao、Service

/**
     * 报修工单 一级下拉选
     * @param domainId
     * @return
     */
    List<OutDictionary> findFirst1();
    /**
     * 报修工单 二级下拉选
     * @param fatherId
     * @return
     */
    List<OutDictionary> findSecond2(Integer fatherId);
    /**
     * 报修工单 三级下拉选
     * @param fatherId
     * @return
     */
    List<OutDictionary> findThird3(Integer fatherId);

4、impl

@Autowired
    private OutDictionaryDao OutDictionaryMapper;

    //报修工单 一级下拉选
    @Override
    public List<OutDictionary> findFirst1() {
        
        return OutDictionaryMapper.findFirst1();
    }
    //报修工单 二级下拉选
    @Override
    public List<OutDictionary> findSecond2(Integer fatherId) {
        
        return OutDictionaryMapper.findSecond2(fatherId);
    }
    //报修工单 三级下拉选
    @Override
    public List<OutDictionary> findThird3(Integer fatherId) {
        
        return OutDictionaryMapper.findThird3(fatherId);
    }

5、Controller层

/**
         * 报修工单一级下拉选
         * @param req
         * @return
         */
        @RequestMapping(value = "/inFirst1", method = RequestMethod.POST)
        @ResponseBody
        public JSONArray inFirst1( HttpServletRequest   req) {
           //Integer domainId =  Integer.parseInt(req.getSession().getAttribute("domainId").toString());
            List<OutDictionary> first = outDictionaryService.findFirst1();
            JSONArray jsonArr = JSONArray.fromObject(first);
            return jsonArr;
        }
        /**
         * 报修工单二级下拉选
         * @param req
         * @return
         */
        @RequestMapping(value = "/inSecond2", method = RequestMethod.POST)
        @ResponseBody
        public JSONArray inSecond2(Integer fatherId,HttpServletRequest   req) {
            //Integer domainId =  Integer.parseInt(req.getSession().getAttribute("domainId").toString());
            List<OutDictionary> second = outDictionaryService.findSecond2(fatherId);
            JSONArray jsonArr = JSONArray.fromObject(second);
            return jsonArr;
        }
        /**
         * 报修工单三级下拉选
         * @return
         */
        @RequestMapping(value = "/inThird3", method = RequestMethod.POST)
        @ResponseBody
        public JSONArray inThird3(Integer fatherId,HttpServletRequest   req) {
            //Integer domainId =  Integer.parseInt(req.getSession().getAttribute("domainId").toString());
            List<OutDictionary> third = outDictionaryService.findThird3(fatherId);
            JSONArray jsonArr = JSONArray.fromObject(third);
            return jsonArr;
        }

6、JS

//一二三级分类  下拉选
        $('#select_first_rep').combobox({
                    url : '${path }' + '/dictionary/inFirst1',
                    valueField : 'id',
                    textField : 'name',
                    onSelect : function() {
                        var xqmc = $('#select_first_rep').combobox('getText');//获取当前选中的
                        var pccode = $('#select_first_rep').combobox('getValues')[0];//获取当前选
                        $('#select_second_rep').combobox({
                             url : '${path }'+'/dictionary/inSecond2?fatherId='+pccode,
                             valueField : 'id',
                             textField : 'name',
                             onSelect : function() {
                                var pccode1 = $('#select_second_rep').combobox('getValues');
                                var fId;
                                if(pccode1!=null){
                                    fId=pccode1[0];
                                }
                                $('#select_third_rep').combobox({
                                    url : '${path }'+'/dictionary/inThird3?fatherId='+fId,
                                     valueField : 'id',
                                     textField : 'name',
                                     onSelect : function() {}
                                     }) 
                             }
                             })
                    }
        })
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • JSPXCMS开发架构介绍 V1 – 架构概述 基本概述 配置文件目录 /src/main/resources/...
    Java_Evan阅读 4,435评论 0 0
  • 本次主要介绍一下网页加载进度的实现。如下图,在页面加载的时候,上方红色的进度条 网页加载进度的好处是能够更好的反应...
    笨坨阅读 2,615评论 0 2
  • 最近参加一场茶会,大家对行业发展各抒己见侃侃而谈。 其中一位自称屌丝的创业者大D哥说他以前读书时爱看一些比如李嘉诚...
    司无伏阅读 541评论 0 0
  • 如果说自卑是人类与自然互动的必然结果,那么勇气就是人们在追寻意义人生中的必然能力。 这是一本读起来便放不下的书。 ...
    琳达梨阅读 401评论 0 1