02_RequestMapping解析和静态资源的访问
zcq
TeamController.java
package com.kkb.controller;
import com.kkb.service.TeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
/**
* ClassName: TeamController
*
* @author wanglina
* @version 1.0
*/
@Controller
@RequestMapping("team")
public class TeamController {
@Autowired
private TeamService teamService;
@RequestMapping(value = "add.do",method = RequestMethod.GET)
public ModelAndView addTeam(){
System.out.println("TeamController----addTeam---");
ModelAndView mv=new ModelAndView();
mv.setViewName("team/add");// 映射成为物理资源路径:/jsp/team/add.jsp
return mv;
}
@RequestMapping(value = "update.do",method = RequestMethod.POST)
public ModelAndView updateTeam(){
System.out.println("TeamController----updateTeam---");
ModelAndView mv=new ModelAndView();
mv.setViewName("team/update");//映射成为物理资源路径:/jsp/team/update.jsp
return mv;
}
@RequestMapping("hello.do")
public ModelAndView hello(){
System.out.println("TeamController----add---");
teamService.add();
ModelAndView mv=new ModelAndView();
mv.addObject("teamName","湖人");//相当于request.setAttrubuite("teanName","湖人");
mv.setViewName("index");//未来经过springmvc的视图解析器处理,转换成物理资源路径,相当于request.getRequestDispatcher("index.jsp").forward();
//经过InternalResourceViewResolver对象的处理之后加上前后缀就变为了 /jsp/index.jsp
return mv;
}
}
team/add.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>ADD</title>
</head>
<body>
<H1>addTeam------------</H1>
</body>
</html>
team/update.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>update</title>
</head>
<body>
<H1>updateTeam------------</H1>
</body>
</html>