1

我在 REST、Spring MVC 中有一个客户端-服务器架构。Tghe 客户端正在访问服务器 URL 并随之发送两个参数。服务器应该使用响应值回复客户端。我正在使用 RestTemplate 访问服务器 URL 的客户端之一。运行时,服务器 URL 被成功访问(服务器端逻辑正在执行),但随后我在客户端收到以下错误:

HTTP Status 400 - 

--------------------------------------------------------------------------------

type Status report

message 

description The request sent by the client was syntactically incorrect ().

客户端代码为:

rresult = restTemplate.getForObject("http://localhost:8081/Merchant/api/movieTheater"+params.toString(), ResponseText.class);

esrver 端代码是:

@ResponseBody
@RequestMapping(value="movieTheater")
public ResponseText getCustomerInput(@RequestParam("name") String name, @RequestParam("price") Double price) {
    System.out.println("Requst URL got accessed here");
    ResponseText result = new ResponseText();
    Transaction transaction = new Transaction();
    transaction.setMovieName(name);
    transaction.setTicketPrice(price);
    transaction.setDatetime(new Date());
    if(transactionService.addTransaction(transaction))
        result.setMessage(ResponseStatus.SUCCESS.getStatus());
    else
        result.setMessage(ResponseStatus.FAILED.getStatus());
    return result;
}                

当我单独访问 URL 时,它工作正常。我不确定我做错了什么。请帮忙!提前致谢!

4

2 回答 2

2

我想到了!!!我有一个用于在客户端创建 JSON 结构的内部类。解决方案是使该类静态!由于它不是静态的,它试图实例化,因此收到错误消息:“无法读取 JSON:找不到适合类型的构造函数”

于 2013-08-13T12:43:49.353 回答
0

我猜网址"http://localhost:8081/Merchant/api/movieTheater"+params.toString()不正确。类名是params什么,方法返回的结果是什么toString()getCustomerInput()访问错误的 URL 时方法无法获取参数值。

网址必须是这样的

http://localhost:8081/Merchant/api/movieTheater?name=xxx&price=1.01
于 2013-08-13T09:04:55.393 回答