@Controller
public class UserController
{
@RequestMapping(value = "/save",method = RequestMethod.POST )
public String save()
{
System.out.println("controller save running...");
return "index.jsp";
}
}
如果指定method为 POST,该浏览器会指定以post方式请求
如果设置请求参数params,客户端请求必须加上params中的参数
@Controller
public class UserController
{
@RequestMapping(value = "/save",method = RequestMethod.GET,params = {"username"})
public String save()
{
System.out.println("controller save running...");
return "index.jsp";
}
}
附:可以指定forword的前缀、后缀
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
在controller层,就可以直接返回success
@RequestMapping("/user")
@Controller
public class UserController
{
@RequestMapping(value = "/save",method = RequestMethod.GET,params = {"username"})
public String save()
{
System.out.println("controller save running...");
return "success";
}
}