Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从spring控制器调用Java模态函数?_Java_Spring_Spring Mvc - Fatal编程技术网

从spring控制器调用Java模态函数?

从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,

我是JavaSpring技术的新手。我想从JavaSpring控制器调用模态中的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;
    }

我想从莫代尔那里买到所有的价格。如何在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()