02_RequestMapping解析和静态资源的访问

zcq

TeamController.java

  1. package com.kkb.controller;
  2. import com.kkb.service.TeamService;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.stereotype.Controller;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. import org.springframework.web.bind.annotation.RequestMethod;
  7. import org.springframework.web.servlet.ModelAndView;
  8. /**
  9. * ClassName: TeamController
  10. *
  11. * @author wanglina
  12. * @version 1.0
  13. */
  14. @Controller
  15. @RequestMapping("team")
  16. public class TeamController {
  17. @Autowired
  18. private TeamService teamService;
  19. @RequestMapping(value = "add.do",method = RequestMethod.GET)
  20. public ModelAndView addTeam(){
  21. System.out.println("TeamController----addTeam---");
  22. ModelAndView mv=new ModelAndView();
  23. mv.setViewName("team/add");// 映射成为物理资源路径:/jsp/team/add.jsp
  24. return mv;
  25. }
  26. @RequestMapping(value = "update.do",method = RequestMethod.POST)
  27. public ModelAndView updateTeam(){
  28. System.out.println("TeamController----updateTeam---");
  29. ModelAndView mv=new ModelAndView();
  30. mv.setViewName("team/update");//映射成为物理资源路径:/jsp/team/update.jsp
  31. return mv;
  32. }
  33. @RequestMapping("hello.do")
  34. public ModelAndView hello(){
  35. System.out.println("TeamController----add---");
  36. teamService.add();
  37. ModelAndView mv=new ModelAndView();
  38. mv.addObject("teamName","湖人");//相当于request.setAttrubuite("teanName","湖人");
  39. mv.setViewName("index");//未来经过springmvc的视图解析器处理,转换成物理资源路径,相当于request.getRequestDispatcher("index.jsp").forward();
  40. //经过InternalResourceViewResolver对象的处理之后加上前后缀就变为了 /jsp/index.jsp
  41. return mv;
  42. }
  43. }

team/add.jsp

  1. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  2. <html>
  3. <head>
  4. <title>ADD</title>
  5. </head>
  6. <body>
  7. <H1>addTeam------------</H1>
  8. </body>
  9. </html>

team/update.jsp

  1. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  2. <html>
  3. <head>
  4. <title>update</title>
  5. </head>
  6. <body>
  7. <H1>updateTeam------------</H1>
  8. </body>
  9. </html>