@Controller
@RequestMapping("/user")
public class UserServlet{
@RequestMapping("/save")
public String save(){
//返回要跳转的页面路径字符串
return "/index.jsp";
}
}
@RequestMapping("/save1")
public ModelAndView save1(ModelAndView miv){
miv.addObject("user","itheima");
miv.setViewName("/index.jsp");
return miv;
}
@RequestMapping("/save2")
public void save2(HttpServletResponse response) throws IOException {
response.setContentType("text/html;charset=utf-8");
response.getWriter().write("save2 success!");
}
@RequestMapping("/save3")
@ResponseBody
public String save3(ModelAndView miv){
return "save3 success!";
}
@RequestMapping("/save4")
@ResponseBody
public User save4(ModelAndView miv){
User user = new User();
user.setName("itheima");
user.setAge(18);
return user;
}
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
</list>
</property>
</bean>
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |