js
$(document).ready(function() { //页面加载时运行此函数 放在最前端
/* 三级联动 */
$.ajax({
url: ctx + "system/school/select",
type: 'GET',
success:function (data) {
$("#aschool").empty();
$("#aschool").append("");
for (var i = 0; i < data.length; i++){
$("#aschool").append("");
}
}
});
$("#aschool").change(function () {//同上面一样
// alert($("#aschool").val())
$.ajax({
url: ctx + "system/grade/select",
type: 'GET',
data: {
scid: $("#aschool").val(),
},
success:function (data) {
$("#agrade").empty();
$("#agrade").append("");
for (var i = 0; i < data.length; i++){
$("#agrade").append("");
}
}
});
});
$("#agrade").change(function () {//同上面一样
// alert($("#agrade").val())
$.ajax({
url: ctx + "system/classes/select",
type: 'GET',
data: {
gid: $("#agrade").val(),
},
success:function (data) {
$("#aclasses").empty();
$("#aclasses").append("");
for (var i = 0; i < data.length; i++){
$("#aclasses").append("");
}
}
})
});
});
GradelService
/* 三级联动 */
public List selectGradeBid1(Integer scid);
ClassesService
//联动
public List selectClassBid1(Integer gid);
SchoolController 最高层
/* 三级联动 */
@GetMapping("/select")
@ResponseBody
public List select(){
List list1 = aschoolService.selectSchoolList(new GXSchool());
return list1;
}
GradeController
/* 三级联动 */
@GetMapping("/select")
@ResponseBody
public List select(Integer scid){
List list1 = gradeService.selectGradeBid1(scid);
return list1;
}
ClassesController
/* 联动 */
@GetMapping("/select")
@ResponseBody
public List select(Integer gid){
List list1 = classesService.selectClassBid1(gid);
return list1;
}
ClassesMapper.xml
GradeMapper.xml
edit.html
js
//联动修改默认
$(document).ready(function () {
//获取controller层的函数,进行默认选中
var gid = [[${gradeId}]];
var scid = [[${schoolId}]];
$("#agrade").val(gid);
// alert(gid);
$("#aschool").val(scid);
},
$("#aschool").change(function () {//同上面一样
$.ajax({
url: ctx + "system/grade/select",
type: 'GET',
data: {
gid: $("#aschool").val(),
},
success:function (data) {
$("#agrade").empty();
$("#agrade").append("");
for (var i = 0; i < data.length; i++){
$("#agrade").append("");
}
}
})
}),
$("#agrade").change(function () {//同上面一样
$.ajax({
url: ctx + "system/classes/select",
type: 'GET',
data: {
gid: $("#agrade").val(),
},
success:function (data) {
$("#aclasses").empty();
$("#aclasses").append("");
for (var i = 0; i < data.length; i++){
$("#aclasses").append("");
}
},
})
}),
)
StudentController
@GetMapping("/edit/{id}")
public String edit(@PathVariable("id") int id, ModelMap mmap){
mmap.put("student", studentService.selectStudentById(id));
mmap.put("school",schoolService.selectSchoolList(new GXSchool()));
mmap.put("grade",gradeService.selectGradeList(new GXGrade()));
//通过id进行判断并且取值,通过id进行逐层查询获取id,先向上准确查询,在向下模糊查询,默认选中在下面。
String classes1= studentService.selectStudentById(id).getCid();
String grade1 = classesService.selectClassesByCid(Integer.parseInt(classes1)).getGid();
int school1 = gradeService.selectGradeBygid(Integer.parseInt(grade1)).getScid();
mmap.put("classId",classes1);
mmap.put("gradeId",grade1);
mmap.put("schoolId",school1);
mmap.put("Grade", gradeService.selectGradeBid1(school1));
mmap.put("Classes", classesService.selectClassBid1(Integer.parseInt(grade1)));
return prefix + "/edit";
}