从spring控制器调用Java模态函数?
我是JavaSpring技术的新手。我想从JavaSpring控制器调用模态中的getFunction从spring控制器调用Java模态函数?,java,spring,spring-mvc,Java,Spring,Spring Mvc,我是JavaSpring技术的新手。我想从JavaSpring控制器调用模态中的getFunction @RequestMapping(value = "/category/pagination-mobile/{categoryId}/{currentCity}", method = RequestMethod.POST) @ResponseBody public Map<String, String> paginationMobile(ModelMap model,
@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;
}
我想从莫代尔那里买到所有的价格。如何在spring controller中获取所有价格。
cityProducts
是列表的对象,操作系统不能调用cityProdycts
对象上的getPrice
方法。您必须重复下面的列表
,才能使用getPrice
方法获取每个产品的价格
@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;
}
for(CityProduct cityProduct : cityProducts){
System.out.println(cityProduct.getPrice());
}
如果您希望实现超价格逻辑,可以在for循环中实现。我希望显示价格的整数。现在是1299.0000。但我想展示1299。我已经在jsp中使用了。我可以在控制器中验证吗?在控制器中使用cityProduct.getPrice().intValueExact()
。