controller:
@ResponseBody
@RequestMapping("findRumByRid")
private Room findRumByRid(HttpServletRequest request, HttpServletResponse response) throws IOException {
return roomMapper.findRumByRid(Integer.parseInt(request.getParameter("rid")));
}
html:
// 显示修改模态框回显数据
function selectAllRoomType1(){
$.ajax({
url: "findAllRoom",
type: "POST",
dataType: "JSON",
async : false,
success: function (resp) {
console.log(resp);
let a = template('choose_dept', {data: resp});
$("#updateDept").html(a);
}
})
}
function showUpdateMod(rid){
selectAllRoomType1()
$(`#updateMod`).modal(`show`);
$.ajax({
url: "findRumByRid",
type: "POST",
dataType: "JSON",
data: {rid: rid},
success: function (resp) {
console.log(resp);
$(`#updateName`).val(resp.rnum);
$('#example-mod option[value="'+resp.type+'"]').attr("selected","selected");
}
})
}
关键代码:
$('#example-mod option[value="'+resp.type+'"]').attr("selected","selected");
运行结果: