第二节 Spring 和 SpringMVC 整合
1、本质
- ContextLoaderListener:读取 spring-persist.xml
- DispatcherServlet:读取 spring-mvc.xml
2、web.xml配置
3、SpringMVC 配置
4、创建组件
@Controller
public class EmpHandler {
@Autowired<br /> private EmpService empService;
@RequestMapping("/get/all")<br /> public String getAll(Model model) {
// 1、查询数据<br /> List<Emp> empList = empService.getAll();
// 2.存入模型<br /> model.addAttribute("empList", empList);
return "emp-list";<br /> }
}
5、页面操作
①首页超链接
②显示数据的页面
ID | NAME | SALARY |
---|---|---|
抱歉!没有查询到数据! | ||
这里显示员工ID | 这里显示员工NAME | 这里显示员工SALARY |