feignClient传参(参数为对象类型)的一个坑
客户端
@RequestMapping(value = "/friendCircleComment/comment",method = RequestMethod.POST)
R comment(@RequestBody FriendCircleComment friendCircleComment);
服务端
@RequestMapping(value = "/comment")
public R comment(@RequestBody FriendCircleComment friendCircleComment){
friendCircleCommentService.comment(friendCircleComment);
return new R();
}
这么传参是没问题的,服务端也能接收到
但是,问题来了,
小程序的post请求的header必须为
header:{ 'content-type':'application/x-www-form-urlencoded' },
导致后台为@RequestBody接收不到参数,
feignClient默认参数请求类型是
header:{ 'content-type':'application/json' },
定义@RequestBody接收参数的headers类型必须为 header:{ 'content-type':'application/json' },
所以这样就有冲突,feignClient和定义为'content-type':'application/x-www-form-urlencoded'的请求接口不能共用
解决方法
不使用对象接收,使用基本类型接收
如下
客户端
@RequestMapping(value = "/friendCircleComment/comment",method = RequestMethod.POST)
R comment(@RequestParam(value = "friendCircleId",required = false)Integer friendCircleId,
@RequestParam(value = "memberId",required = false)Integer memberId,
@RequestParam(value = "parentId",required = false)Integer parentId,
@RequestParam(value = "comment",required = false)String comment,
@RequestParam(value = "replyMemberId",required = false)Integer replyMemberId);
服务端
@RequestMapping(value = "/comment")
public R comment(@RequestParam(value = "friendCircleId",required = false)Integer friendCircleId,
@RequestParam(value = "memberId",required = false)Integer memberId,
@RequestParam(value = "parentId",required = false)Integer parentId,
@RequestParam(value = "comment",required = false)String comment,
@RequestParam(value = "replyMemberId",required = false)Integer replyMemberId
){
FriendCircleComment friendCircleComment = new FriendCircleComment();
friendCircleComment.setFriendCircleId(friendCircleId);
friendCircleComment.setMemberId(memberId);
friendCircleComment.setParentId(parentId);
friendCircleComment.setComment(comment);
friendCircleComment.setReplyMemberId(replyMemberId);
friendCircleCommentService.comment(friendCircleComment);
return new R();
}
feignClient传参(参数为对象类型)的一个坑的更多相关文章
- javascript之url转义escape()、encodeURI()和decodeURI(),ifram父子传参参数有中文时出现乱码
ifram父子传参参数有中文时出现乱码,可先在父级页面用encodeURI转义,在到子页面用进行decodeURI()解码 我们可以知道:escape()除了 ASCII 字母.数字和特定的符号外,对 ...
- ajax传参data里面的键是一个变量的解决方法
直接用这种方式来传参,比如bean中有字段 username password,则是 data[username] = "用户名"; data[password] = " ...
- 使用springmvc从页面中获取数据,然后根据获得的参数信息进行修改,如果修改的数据中含有不是基本数据类型的参数。比如传的参数中有Date类型的数据时,需要我们进行参数类型转换。
1.1 需求 在商品修改页面可以修改商品的生产日期,并且根据业务需求自定义日期格式. 1.2 需求分析 由于日期数据有很多格式,所以springmvc没办法把字符串转换成日期类型.所以需要自定义参数绑 ...
- Asp.net MVC中文件上传的参数转对象的方法
参照博友的.NET WebApi上传文件接口(带其他参数)实现文件上传并带参数,当需要多个参数时,不想每次都通过HttpContext.Request.Params去取值,就针对HttpRequest ...
- 微信小程序跳转传参参数丢失?
垂死病中惊坐起,笑问 Bug 何处来?! 1.先是大写字母作祟 前两天发布了「柒留言」v2.0.0 新版本,结果...你懂的嘛,没有 Bug 的程序不是好程序,写不出 Bug 的程序员不是好程序员. ...
- [UE4]创建多把枪,使用Class,参数的对象类型
先来说说函数输入参数的区别: 1.Object Reference 2.Class Reference 会出现可以让你选择一个类 3.Soft Object Reference 4.Soft Clas ...
- C#,启动exe程序并传参(参数间带&符号)方法
入参格式例如:C:\\Users\\Administrator\\Desktop\\测试\\测试\\bin\\Debug\\测试.exe type=1^&card_no=123 public ...
- JS基础之传参(值传递、对象传递)
一.概念 我们需了解什么是按值传递(call by value),什么是按引用传递(call by reference).在计算机科学里,这个部分叫求值策略(Evaluation Strategy). ...
- Java String引起的常量池、String类型传参、“==”、“equals”、“hashCode”问题 细节分析
在学习javase的过程中,总是会遇到关于String的各种细节问题,而这些问题往往会出现在Java攻城狮面试中,今天想写一篇随笔,简单记录下我的一些想法.话不多说,直接进入正题. 1.String常 ...
随机推荐
- 01 - Jmeter4.x环境安装以及简单使用
Jmeter 介绍 Apache JMeter应用程序是开源软件,旨在为负载测试功能行为和测量性能的100%纯Java应用程序.它最初是为测试Web应用程序而设计的,但后来扩展到其他测试功能 常用压力 ...
- Dedecms织梦后台登陆验证码不显示几种解决方法
Dedecms织梦后台登陆验证码不显示几种解决方法,服务器所造成的验证码不显示问题看这里: 方法一:查看服务器的php版本是否与程序版本兼容(织梦程序PHP版本查看方法:打开www.96net.com ...
- 17-正交矩阵和Gram-Schmidt正交化
一.视频链接 1)正交矩阵 定义:如果一个矩阵,其转置与自身的乘积等于单位向量,那么该矩阵就是正交矩阵,该矩阵一般用Q来表示,即$Q^TQ=QQ^T=I$,也就是$Q^T=Q^{-1}$,即转置=逆 ...
- 在Linux服务器上运行jar包,并且使jar包一直处于后台执行
1.我jar包在linux的目录为/a/bbb.jar 正常情况下,使用在/a目录下使用 java -jar bbb.jar 可以直接运行该jar包的项目,运行成功之后使用crtl+ ...
- Sass-@for
在制作网格系统的时候,大家应该对 .col1~.col12 这样的印象较深.在 CSS 中你需要一个一个去书写,但在 Sass 中,可以使用 @for 循环来完成.在 Sass 的 @for 循环中有 ...
- C#基础知识之类和结构
虽然项目中一直在使用类.结构体等类型,仔细琢磨,还真无法系统的说出个所以然.记录一下类.结构体.类和结构体区别 一.类 对于类,大家都特别熟悉.简单的介绍一下类的结构,然后记录一下Class需要注意的 ...
- OpenCV图像数据字节对齐
目录 1. IplImage的data字段,是char*类型,是4字节对齐. 2. 手动创建的Mat通常是没有字节对齐的 3. 从IplImage转过来的Mat,是字节对齐的 4. 总结 图像数据是否 ...
- Strcpy,strcpy使用注意
一.char *strcpy(char *dest, const char *src) 参数 dest -- 指向用于存储复制内容的目标数组. src -- 要复制的字符串. 注意: 1.dest需要 ...
- 小程序之背景音乐——wx.backgroundAudioManager
var that = this; const back = wx.getBackgroundAudioManager(); back.onPlay(() => { console.log(&qu ...
- canvas 操作像素 窗帘效果
代码实例: <!DOCTYPE html> <html> <head> <style> canvas{ background:#eee; } </ ...