我是java spring技术的新手。我想从java spring controller中调用modal中的getFunction。
@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 :(得分:0)
cityProducts
是List
的对象,您无法在getPrice
对象上调用cityProdycts
方法。您必须迭代List
,如下所示,使用getPrice
方法获取每种产品的价格。
for(CityProduct cityProduct : cityProducts){
System.out.println(cityProduct.getPrice());
}
如果你想要一些逻辑来实现超价,你可以在for循环中实现。