gpt4 book ai didi

java - Spring - 为什么返回值在屏幕中显示 XML 类型?

转载 作者:行者123 更新时间:2023-12-01 20:14:46 25 4
gpt4 key购买 nike

我有一个问题。我正在使用Spring框架,我想返回Json数据

当我调用时,它会在 Postman 中返回 XML 类型。

但在控制台中打印了 Json 类型

这是 Controller

@Autowired
MobileUserService mobileUserService;

@RequestMapping(value = "/mobile/mobileuser.do")
@ResponseBody
public HashMap<String, Object> selectUser(
@RequestParam(value="userId", required = false) String userId,
@RequestParam(value="userPwd", required = false) String userPwd,
HttpServletRequest request) {
HashMap<String, Object> selectMap = mobileUserService.selectUser(userId, userPwd);

System.out.println("userid: " + userId + "userPW : " + userPwd);

if(selectMap == null) {
selectMap = new HashMap<String, Object>();
selectMap.put("code", -1);
selectMap.put("msg", "Check ID or Password");
}else {
selectMap.put("code", 0);
selectMap.put("msg", "Success");
}
System.out.println("sdfsdfsdf " + selectMap);
return selectMap;
}

我在 pom.xml 中添加了依赖项

<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>

服务器上下文.xml

<bean id=“jacksonMessageConverter” class=“org.springframework.http.converter.json.MappingJackson2HttpMessageConverter”/>

我怎么能这样?

最佳答案

将您的请求映射更改为

@RequestMapping(method = RequestMethod.GET, produces = "application/json")

关于java - Spring - 为什么返回值在屏幕中显示 XML 类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46110106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com