通过request获取body中的内容

公众号:踏歌的 Java Daily

上代码

 	@Autowired
    private pervice perviceService;
	@RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("获取信息")
    public OfferOrderReturn add(HttpServletRequest request, HttpServletResponse response) {
        try {
            //request获取输入流
            BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
            //读取输入流的内容转换为String类型IOUtils必须引入org.apache.dubbo.common.utils.IOUtils;包
            String body = IOUtils.read(reader);
            System.out.println(body );
            perviceService.index(body);
        } catch (Exception e) {
            LOG.info("*****存在问题*****");
        } finally {
        }
        //如果需要返回值并且try有返回值此时只需要返回null
        return null;
    }

创作不易请多多支持,更多详情请关注wx工作号:xvguo1127

你可能感兴趣的:(java)