SpringMVC因为添加了下面这个bean 视图解析器 当你方法返回的是 json 、字符串等其它值时, 会404
跳转 jsp/*.jsp页面
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
</bean>
下面这个返回的是 跳转jsp页面
@RequestMapping(value = "get_xx.do",method = RequestMethod.GET)
public String get_information(HttpSession session, ModelMap map){
String currentUser = (String) session.getAttribute("username");
if(currentUser == null){
return "index";
}
map.put("userList",userList);
return "user_management_show"; //跳转页面
}
页面有需求是返回字符串
@RequestMapping(value = "findDeptName.do",method = RequestMethod.GET)
@ResponseBody //要求返回的是信息 如果去掉就返回 jsp/*.jsp页面
public String getDeptNameByid(Integer devId){
return derviceService.getDeptName(devId); //有注解,所以返回的是查询出来的字符串
}
@ResponseBody //有这个注解的时候返回结果直接写入HTTP response body中,不会被解析为跳转路径。比如异步请求,希望响应的结果是json数据,那么加上@responsebody后,就会直接返回json数据。