2017-01-09 20 views
0

私はjava spring technologyの新機能です。私は、Java Spring ControllerからモーダルでgetFunctionを呼び出す必要があります。Spring ControllerからJava Modal関数を呼び出しますか?

@RequestMapping(value = "/category/pagination-mobile/{categoryId}/{currentCity}", method = RequestMethod.POST) 
    @ResponseBody 
    public Map<String, String> paginationMobile(ModelMap model, @PathVariable int categoryId, @PathVariable int currentCity, HttpServletRequest request, HttpServletResponse response) { 
     Map<String, String> resp = new HashMap<>(); 
     List<CityProduct> cityProducts = productService.getCityProductsForCategoryForWeb(categoryId, currentCity, 15, false); 
     request.setAttribute("products", cityProducts); 
     request.setAttribute("categoryId", categoryId); 
     System.out.println("--------------> " + cityProducts.getPrice()); 
     String paginationFirstPage = getHtmlResponse(request, response, "/WEB-INF/jsp/catalog/_categoryFirst.jsp"); 
     resp.put("html", paginationFirstPage); 
     return resp; 
    } 

の.java

public class CityProduct implements Serializable { 
public CityProduct(Product p, ProductOfCity pc) { 
this.price = pc.getPrice(); 

} 

public BigDecimal getPrice() { 
     return price; 
    } 

    public void setPrice(BigDecimal price) { 
     this.price = price; 
    } 

} 

私は、モーダルからすべての価格を取得したいです。春のコントローラですべての価格を取得する方法。

答えて

0

cityProductsは、Listのオブジェクトです。cityProdyctsオブジェクトでは、getPriceメソッドを呼び出すことはできません。 getPriceメソッドを使用して各製品の価格を取得するには、以下のようにListを反復処理する必要があります。

for(CityProduct cityProduct : cityProducts){ 
    System.out.println(cityProduct.getPrice()); 
} 

ロジックを値段以上に実装したい場合は、forループで実行できます。

+0

私は価格の整数を表示したいと思います。今は1299.0000です。しかし私は1299を表示したいと思います。私はすでにJSPでを使用しています。コントローラで検証できますか? –

+0

あなたのコントローラで 'cityProduct.getPrice()。intValueExact()'を使用してください。 – Avinash

関連する問題