[[toc]]

第二节 Spring 和 SpringMVC 整合

1、本质

  • ContextLoaderListener:读取 spring-persist.xml
  • DispatcherServlet:读取 spring-mvc.xml

2、web.xml配置




contextConfigLocation
classpath:spring-persist.xml



org.springframework.web.context.ContextLoaderListener



dispatcherServlet
org.springframework.web.servlet.DispatcherServlet

contextConfigLocation
classpath:spring-mvc.xml

1


dispatcherServlet
/




characterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter

encoding
UTF-8


forceRequestEncoding
true


forceResponseEncoding
true



characterEncodingFilter
/*



hiddenHttpMethodFilter
org.springframework.web.filter.HiddenHttpMethodFilter


hiddenHttpMethodFilter
/*

3、SpringMVC 配置























4、创建组件

02 Spring 和 SpringMVC 整合 - 图1

@Controller
public class EmpHandler {

  1. @Autowired<br /> private EmpService empService;
  2. @RequestMapping("/get/all")<br /> public String getAll(Model model) {
  3. // 1、查询数据<br /> List<Emp> empList = empService.getAll();
  4. // 2.存入模型<br /> model.addAttribute("empList", empList);
  5. return "emp-list";<br /> }

}

5、页面操作

①首页超链接

02 Spring 和 SpringMVC 整合 - 图2

显示全部数据

②显示数据的页面

02 Spring 和 SpringMVC 整合 - 图3



















ID NAME SALARY
抱歉!没有查询到数据!
这里显示员工ID 这里显示员工NAME 这里显示员工SALARY

回首页

上一节 回目录 下一节