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() {}
})
}
})
}
})
网友评论