feignClient transmission parameters (parameters for the object type) of a pit

Client

    @RequestMapping(value = "/friendCircleComment/comment",method = RequestMethod.POST)
    R comment(@RequestBody FriendCircleComment friendCircleComment);

Server

1   @RequestMapping(value = "/comment")
2   public R comment(@RequestBody FriendCircleComment friendCircleComment){
3     friendCircleCommentService.comment(friendCircleComment);
4     return new R();
5   }

So mass participation is no problem, the server can receive the

However, the question is,

post request header applet must be

  header:{ 'content-type':'application/x-www-form-urlencoded'  }, 

It causes a background not receive parameters @RequestBody,

Type definition @RequestBody headers received parameter must header: { 'content-type'  : 'application / json'}, 

Therefore, so there is a conflict, feignClient and is defined as the 'content-type': 'application / x-www-form-urlencoded' request can not be shared interfaces

Solution

Receiving an object is not used, the use of the basic type of the received

as follows

Client

1     @RequestMapping(value = "/friendCircleComment/comment",method = RequestMethod.POST)
2     R comment(@RequestParam(value = "friendCircleId",required = false)Integer friendCircleId,
3               @RequestParam(value = "memberId",required = false)Integer memberId,
4               @RequestParam(value = "parentId",required = false)Integer parentId,
5               @RequestParam(value = "comment",required = false)String comment,
6               @RequestParam(value = "replyMemberId",required = false)Integer replyMemberId);

Server

 1   @RequestMapping(value = "/comment")
 2   public R comment(@RequestParam(value = "friendCircleId",required = false)Integer friendCircleId,
 3                    @RequestParam(value = "memberId",required = false)Integer memberId,
 4                    @RequestParam(value = "parentId",required = false)Integer parentId,
 5                    @RequestParam(value = "comment",required = false)String comment,
 6                    @RequestParam(value = "replyMemberId",required = false)Integer replyMemberId
 7                    ){
 8     FriendCircleComment friendCircleComment = new FriendCircleComment();
 9     friendCircleComment.setFriendCircleId(friendCircleId);
10     friendCircleComment.setMemberId(memberId);
11     friendCircleComment.setParentId(parentId);
12     friendCircleComment.setComment(comment);
13     friendCircleComment.setReplyMemberId(replyMemberId);
14     friendCircleCommentService.comment(friendCircleComment);
15     return new R();
16   }

 

Guess you like

Origin www.cnblogs.com/suruozhong/p/11454505.html