从request中获取只需要3步骤即可,其中会用到dubbo的IOUtils,需要引入maven
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
</dependency>
具体业务代码如下:
import java.io.BufferedReader;
import com.alibaba.dubbo.common.utils.IOUtils;
BufferedReader bufferedReader = request.getReader();
String bodyStr = IOUtils.read(bufferedReader);
Map<String, Object> map = CommUtil.JSON2Map(bodyStr);
用到的JSON2Map方法是我自己封装的一个json字符串转map的方法,代码如下:
import com.alibaba.fastjson.JSON;
Map<String, Object> map = new HashMap<String, Object>();
map = (Map<String, Object>) JSON.parse(obj);
需要引入alibaba的json工具:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.49</version>
</dependency>