3.1、在web下面创建controller类(com.fzj.sss.controller.Em_infoController)
编写findAll()方法,把返回值list加入modelAndView,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
@Controller @RequestMapping ( "/em_info" ) public class Em_infoController { @Autowired private IEm_infoService em_infoService; @RequestMapping ( "/findAll.do" ) public ModelAndView findAll() throws Exception{ ModelAndView mv = new ModelAndView(); List<Em_info> em_infoList = em_infoService.findAll(); for (Em_info em:em_infoList ) { System.out.println(em.getEm_name()); } mv.addObject( "em_infoList" ,em_infoList); mv.setViewName( "em_info" ); return mv; } } |
4、页面:
Index.Jsp 添加超连接
1
|
< a href="${pageContext.request.contextPath}/em_info/findAll.do">查询所有</ a > |
创建结果展示页面em_info.jsp
通过${em_infoList}EL表达式获取值,并表格通过foreche循环展现数值
把项目web的war包部署到tomcat