1、在页面新增一个方法getDepts() function getDepts() { $.ajax({ url:"${APP_PATH}/depts", type:"get", success:function(result) { console.log(result); } }); }
2、创建一个业务逻辑层DepartmentServicepackage com.gwolf.crud.service;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import com.gwolf.crud.bean.Department;import com.gwolf.crud.dao.DepartmentMapper;@Servicepublic class DepartmentService { @Autowired private DepartmentMapper departmentMapper; public List<Department> getDepts() { return this.departmentMapper.selectByExample(null); }}
3、新建一个DepartmentController控制类,用于部门信息的查询。package com.gwolf.crud.controll髫潋啜缅er;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.ResponseBody;import com.gwolf.crud.bean.Department;import com.gwolf.crud.bean.Msg;import com.gwolf.crud.service.DepartmentService;@Controllerpublic class DepartmentController { @Autowired private DepartmentService departmentService; @ResponseBody @RequestMapping("/depts") public Msg getDepts() { List<Department> list = this.departmentService.getDepts(); return Msg.success().add("depts", list); }}
4、在浏览器控制台查看是否数据已经返回
5、显示部门部门信息在bootst筠续师诈rap模态对话框的下拉列表之中function getDepts() { $.aj锾攒揉敫ax({ url:"${APP_PATH}/depts", type:"get", success:function(result) { $.each(result.extend.depts,function() { var optionEle = $("<option></option>").append(this.deptName).attr("value",this.deptId); optionEle.appendTo($("#dept_select")); }); } }); }
6、在浏览器中查看模态对话框的下拉列表数据是否成功。