[REST] rop框架支持参数MAP的请求吗?

jindez 2016-08-26
目前在使用ROP框架过程中,需要传入变参的问题,使用了map,发送请求到后台报错。不知道有没有碰到过这种情况的
我的一切有我 2016-08-28
可以定义一个map集合的实现RopConverter接口的转换器,只要你的转换器能够正确的将map集合转换成字符串,也能正确的将相应的字符串转换成map集合对象就可以,别忘记在spring配置文件相应的地方配置哦。
jindez 2016-09-02
这么ROP开源代码怎么这几年没有更新呢?
我的一切有我 2016-09-02
估计是作者忙,没空维护了,rop框架本身就是作者的一时兴起开源出来的,没利益维持谁会经常维护呢?
wen_xudong7 2016-09-25

支持的,我写了一个测试例,你可以参考下:

public class TestRequest extends AbstractRopRequest {

    @Valid
    private Map<String, String> params;

    public Map<String, String> getParams() {
        return params;
    }

    public void setParams(Map<String, String> params) {
        this.params = params;
    }

}

 

public class TestService {

    public static final String APP_KEY    = "c339f406cc4fcd247ebebd8c2ef04961";
    public static final String APP_SECRET = "e087854ec655c113a8046cd4a208f3f7";
    public static final String SERVER_URL = "http://127.0.0.1:8080/router";

    /**
     * testSearch(测试用例)
     * @Exception 异常对象
     */
    @org.junit.Test
    public void testSearch() throws Exception {
        RestTemplate restTemplate = new RestTemplate();
        MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
        form.add("method", "dfire.test.search");
        form.add("appKey", APP_KEY);
        form.add("v", "1.0");
        form.add("locale", "zh_CN");
        form.add("timestamp", String.valueOf(System.currentTimeMillis()));

        TestRequest test = new TestRequest();
        Map<String,String> params = new HashMap<>();
        params.put("name","maodou");
        test.setParams(params);
        form.add("test", JsonUtil.beanToJson(test));

        //对请求参数列表进行签名
        String sign = RopUtils.sign(form.toSingleValueMap(), APP_SECRET);
        form.add("sign", sign);

        String response = restTemplate.postForObject(SERVER_URL, form, String.class);
        System.out.println("response:\n" + response);
    }
}
/**
 * @author maodou
 * @version 1.0
 */
@ServiceMethodBean
public interface TestService {

    /**
     * testSearch 测试用例
     * @param request 参数描述
     * @return Boolean 返回值描述
     * @Exception 异常对象
     */
    @ServiceMethod(method = "dfire.test.search", needInSession = NeedInSessionType.NO, version = "1.0", httpAction = HttpAction.POST)
    Result<Boolean> testSearch(TestRequest request);
}
 
/**
 * @author "maodou"
 * @version 1.0
 */
@ServiceMethodBean(version = "1.0")
public class TestServiceImpl implements TestService {

        
    @Override
    public Result<Boolean> testSearch(TestRequest request) {
        Result<Boolean> result = new ResultSupport<>();
        try {
            RopRequestContext requestContext = request.getRopRequestContext();
            String json = requestContext.getParamValue("test");
            System.out.println(json);
        } catch (BizException e) {
            return new ResultSupport(e.getCode(), e.getMessage());
        }
        return result;
    }
}
 
返回参数:{"ropRequestContext":null,"params":{"name":"maodou"}}

 

Global site tag (gtag.js) - Google Analytics