我使用

Java / Spring MVC RESTful应用程序,并在执行POST请求时获得400 HTTP状态错误.提供了@RestController方法,

@RequestMapping(value = "/generateAddress", method = RequestMethod.POST)

public ResponseEntity generateAddress(@RequestParam("walletName") String walletName,

@RequestParam("currencyName") String currencyName) {

logger.info("walletName {} and currencyName {}", walletName, currencyName);

// return if the wallet name or the currency is null

if (Objects.isNull(walletName) || Objects.isNull(currencyName)) {

return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE);

}

WalletInfo walletInfo = walletService.generateAddress(walletName, currencyName);

if (Objects.isNull(walletInfo)) {

return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE);

}

WalletInfoWrapper walletInfoWrapper = new WalletInfoWrapper();

walletInfoWrapper.setName(walletInfo.getName());

return new ResponseEntity(walletInfoWrapper, HttpStatus.CREATED);

}

邮递员的POST请求在下面提供,

错误消息通知,必需字符串参数’walletName’不存在

我还可以提供服务和数据库层的代码,以便观察下拉操作.这是什么问题?

UPDATE

我像这样更新了Postman请求并且仍然有相同的错误,

更新1

我还有同样的问题,

我发布了数据,

{"walletName":"puut","currencyName":"Bitcoin"}

代码如下,

@RequestMapping(value = "/generateAddress", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)

public ResponseEntity generateAddress(@RequestBody WalletWithMoneyRequest walletWithMoneyRequest) {

String walletName = walletWithMoneyRequest.getWalletName();

String currencyName = walletWithMoneyRequest.getCurrencyName();

logger.info("walletName {} and currencyName {}", walletName, currencyName);

// return if the wallet name or the currency is null

if (Objects.isNull(walletName) || Objects.isNull(currencyName)) {

return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE);

}

WalletInfo walletInfo = walletService.generateAddress(walletName, currencyName);

if (Objects.isNull(walletInfo)) {

return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE);

}

WalletInfoWrapper walletInfoWrapper = new WalletInfoWrapper();

walletInfoWrapper.setName(walletInfo.getName());

return new ResponseEntity(walletInfoWrapper, HttpStatus.CREATED);

}

提供POJO,

private class WalletWithMoneyRequest {

String walletName;

String currencyName;

public WalletWithMoneyRequest(String walletName, String currencyName) {

this.walletName = walletName;

this.currencyName = currencyName;

}

public WalletWithMoneyRequest() {

}

public String getWalletName() {

return walletName;

}

public String getCurrencyName() {

return currencyName;

}

public void setCurrencyName(String currencyName) {

this.currencyName = currencyName;

}

public void setWalletName(String walletName) {

this.walletName = walletName;

}

}

这是错误消息,

这里是Tomcat服务器信息,

org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver: 08/19/2017 19:45:55 - Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot construct instance of `mobi.puut.controllers.WalletRestController$WalletWithMoneyRequest` (although at least one Creator exists): can only instantiate non-static inner class by using default, no-argument constructor; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `mobi.puut.controllers.WalletRestController$WalletWithMoneyRequest` (although at least one Creator exists): can only instantiate non-static inner class by using default, no-argument constructor

at [Source: (PushbackInputStream); line: 1, column: 2]

Tomcat Localhost日志

Tomcat Catalina日志

java httppost 400_java – HTTP状态400 – 必需字符串参数’walletName’不存在相关推荐

  1. java 字符码查询_Java URL查询字符串参数的编码

    URLEncoder应该是走的路.您只需要记住,只编码单个查询字符串参数名称和/或值,而不是整个URL,确保不要查询字符串参数分隔符字符&也不是参数名称 – 值分隔符字符=. String q ...

  2. Java编程思想 第十三章:字符串

    1.不可变String String对象是不可变的,每一个看似修改了String值的方法,实际上都是创建了一个全新的String对象. public class Immutable {public s ...

  3. java 线程一直运行状态_详解JAVA 线程-线程的状态有哪些?它是如何工作的?

    线程(Thread)是并发编程的基础,也是程序执行的最小单元,它依托进程而存在. 一个进程中可以包含多个线程,多线程可以共享一块内存空间和一组系统资源,因此线程之间的切换更加节省资源.更加轻量化,也因 ...

  4. 不使用java内置函数,将String字符串转换为int类型

    package com.test;public class AtoiTest {public static void main(String[] args) throws Exception {Str ...

  5. java如何将数据保存为xml6_用Java实现可保存状态的数据库生成XML树,源码来了(9)...

    用Java实现可保存状态的数据库生成XML树,源码来了(9) 时间:2006/7/19 5:38:30 作者:佚名 人气:30 6.3.2.Servlet源码 1.RefreshServlet.jav ...

  6. 面试官问:为什么 Java 线程没有 Running 状态?我懵了

    转载自 面试官问:为什么 Java 线程没有 Running 状态?我懵了 什么是 RUNNABLE? 与传统的ready状态的区别 与传统的running状态的区别 当I/O阻塞时 如何看待RUNN ...

  7. Java中获得了方法名称的字符串,怎么样调用该方法

    问题: Java中获得了方法名称的字符串,怎么样调用该方法 如果我有以下两个变量 Object obj; String methodName = "getName"; 在不知道ob ...

  8. java调用python,传参json字符串,含中文传参

    java调用python,传参json字符串 python脚本内容(test.py) # -*- coding: utf-8 -*-def main(input):return input java调 ...

  9. java字符后移_java把字符串参数往后移3位后输出

    //我想把字符串参数往后移3位后输出packagepassword;importjava.io.IOException;classjiami{Strings1;Stringjiami(Strings) ...

最新文章

  1. 从小白到精通python要多久-小白学Python需要多久?老男孩Python培训教程
  2. win32下多线程同步方式之临界区,互斥量,事件对象,信号量
  3. 【分析】在线交易开启跨境电商B2B新纪元
  4. 将dataGridView数据转成DataTable
  5. 在Win上做Python开发?当然是用官方的MS Terminal和VS Code了
  6. 空间留言软件_电脑硬盘空间提示不足,原来还可以这么做,真是学到老活到老...
  7. 王道考研 计算机网络5 分层结构 协议 服务 接口
  8. c++调用Libsvm
  9. 惠普台式电脑引导不了系统_远程系统重装电脑维修笔记本台式xpwin7810系统启动安装64位32位专业版家...
  10. Spring AOP之注解配置篇
  11. arm搭建云手机教程_云计算培训教程学习路线视频源码课件:seafile私有网盘搭建...
  12. 模糊pid算法实现(Java)
  13. VC 2012 visualstudio的项目属性表 .props文件
  14. 荣耀4a android art,荣耀4A黑科技大揭秘,真是给工程师给跪了!!
  15. 韩 天峰:关于PHP程序员技术职业生涯规划
  16. Auto.js Pro安卓免ROOT引流脚本开发系列教程27网易公开课(5)-UI界面构建
  17. 【BZOJ1014】【JSOI2008】火星人prefix Splay处理区间,hash+dichotomy(二分)check出解...
  18. 搞笑小品剧本-- 搞笑《英雄》——气晕张艺谋
  19. html怎么自动导入数据并排序,jQuery html表格排序插件:tablesorter
  20. 基于Simulink的雷达系统射频前端建模仿真(附源码)

热门文章

  1. vue项目原理分析-2:路由
  2. MapInfo MapXtreme 2005 WebGIS 简单鹰眼设计(转)
  3. Node js npm 包管理工具的基本使用
  4. 数据库 之 事务控制和隔离级别
  5. 07-OSPF区域类型--NSSA区域/完全NSSA区域
  6. linux账号登陆安全性相关命令
  7. HTTP请求过滤器FreeBSD accf_http)
  8. 选择不相交区间(贪心:求不相交区间最多个数)
  9. UVA 10004 Bicoloring
  10. python boxplot用法_Boxplot的介绍和使用