spring MVC 4.3.1和jackson2.5.0总是出问题

asa5880 asa5880 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
功能只想能输出json数据

工具: idea 2016.2.1 没有mevan构建,直接引用jar包, spring MVC 4.3.1和 jackson2.5 (jackson-annotations-2.5.0.jar 、jackson-core-2.5.0.jar、jackson-databind-2.5.0.jar), 用的tomcat8.5
java文件:

@Controller
public class UserController {

@RequestMapping(value="/user", method= RequestMethod.GET)
public @ResponseBody User hello() throws IOException {
User user = new User();
user.setName("test");
user.setPassword("123");
return user;
}
}

spring配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


<context:annotation-config />
<context:component-scan base-package="com.test" />


<bean id = "User" class="com.test.User"></bean>


<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"></bean>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"></bean>

<!-- ViewResolver -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp"/>
<property name="suffix" value=".jsp"/>
</bean>

</beans>

...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
asa5880
Web 开发 81,108 成员 341,721 内容