2

ここに問題があり、あなたの助けが必要です。

コントローラからjspに整数値を取得しようとしています。

私のjspには、ajax呼び出しがあります。

$("#hdnCustomerSize").load(contextPath+"/customer/size", function() {
// some codes
});

私のコントローラーでは:

@RequestMapping(method = RequestMethod.GET, value="/size")
public void getCustomerSize(Model model) {
   model.addAttribute("customerSize", customerService.getCustomers().size());
}

私の問題は、Imが例外を取得することです。

javax.servlet.ServletException: Could not resolve view with name 'customer/size' in servlet with name 'tombuyandsell'.

私は意図的にこれをにマップしなかったので、私はこの例外を取得していることを知っていますviews.propertiessizeその理由は、jspページ全体ではなく、整数値のみを取得したいからです。助けてください。

4

2 に答える 2

2

注釈を使用して@ResponseBody、intを文字列として返します。@ResponseBodyリターンタイプがレスポンスHTTPボディに書き込まれます。

@RequestMapping(method = RequestMethod.GET, value="/size")
@ResponseBody
public String getGroupChatSize(Model model) {
   return Integer.toString(customerService.getCustomers().size());
}

ドキュメンテーション

于 2012-11-16T01:34:20.143 に答える
1

@ResponseBodyで試してください:

@ResponseBody
@RequestMapping(method = RequestMethod.GET, value="/size")
public int getGroupChatSize() {
    return customerService.getCustomers().size();
}
于 2012-11-16T01:34:29.310 に答える