伊人博客 一款有技术又有生活的博客

解决SpringMVC中直接将对象转成JSON输出,提示没有视图的情况

发布时间:2017-04-06 16:09:53 标签: | 阅读(2071)
@RestController
@RequestMapping("/users")
public class UsersController {
	@Resource
	private IUserService userService;
	
	//重要的是@ResponesBody
	@ResponseBody
	@RequestMapping(method=RequestMethod.GET)
	public UserTest testUser() {
		UserTest userTest = userService.getUserById(1);
		return userTest;
	}
}

当JavaWeb作为app的api程序时,需要将对象直接转成JSON,而不需要视图,也就是使用比较流行的RESTFUL方式,结果发现每次访问提示找不到users.jsp,即以下问题,找了很多解决方案,都不行,后来发现竟然是一个小小的问题导致的,记录一下

HTTP Status 404 - /xxxServer/WEB-INF/jsp/users.jsp

type Status report

message /CabangsServer/WEB-INF/jsp/users.jsp

description The requested resource is not available.


Apache Tomcat/8.0.8

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
    <!-- 想要直接显示JSON,没有视图,那么需要添加下边的一句
    后来检查好像也没事,重要的是@ResponesBody -->
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
</bean>

   


原创文章如转载,请注明出处“伊人博客

站内搜索
关注公众号(随时搜索)
文章归档
热门推荐
随机推荐
冷门晾晒