// example /userbase/multi/1345,abc,efg?count=20&cki=true @RequestMapping(value = "/userbase/multi/{params}", method = RequestMethod.GET) public ModelAndView recommandToMany( @PathVariable("params") String params, @RequestParam(value = "count", required = false) Integer count, @RequestParam(value = "cki", required = false) Boolean cki) throws SuggestEngineException { ModelAndView mav = new ModelAndView(); mav.setViewName("home"); HashMap<String, String> map = new HashMap<String, String>(); StringBuilder url_param = new StringBuilder(); String[] userId = params.split(","); logger.info("Id num " + userId.length); for (int i = 0; i < userId.length; i++) { logger.info("userId: " + userId[i]); url_param.append("{userId_" + i + "}/"); map.put("userId_" + i, userId[i]); } if (null != count) map.put("size", String.valueOf(count)); else map.put("size", PropertiesUtil.getRecommendListDefalutCount()); if (null != cki) map.put("cki", String.valueOf(cki)); else map.put("cki", PropertiesUtil.getRecommendListDefalutCKI()); logger.info("count " + count); logger.info("cki " + cki); RecommendList list = recommendService.recommendToMany(url_param.toString(), map); String str = list.getList().get(0).get(0); mav.addObject("list", str); return mav; }
// example /userbase/single/12345 @RequestMapping(value = "/userbase/single/{userId}", method = RequestMethod.GET) public ModelAndView recommandToSingle( @PathVariable("userId") String userId, @RequestParam(value = "count", required = false) Integer count, @RequestParam(value = "cki", required = false) Boolean cki) throws SuggestEngineException { ModelAndView mav = new ModelAndView(); mav.setViewName("responseXml"); HashMap<String, String> map = new HashMap<String, String>(); map.put("userId", userId); if (null != count) map.put("size", String.valueOf(count)); else map.put("size", PropertiesUtil.getRecommendListDefalutCount()); if (null != cki) map.put("cki", String.valueOf(cki)); else map.put("cki", PropertiesUtil.getRecommendListDefalutCKI()); RecommendList list = recommendService.recommendToSingle(map); // throw exception RecommandResponse recommandResponse = new RecommandResponse(); List<RecommandItem> reclist = new ArrayList<RecommandItem>(); for (ArrayList<String> temp : list.getList()) { RecommandItem recommandItem = new RecommandItem(); recommandItem.setId(temp.get(0)); recommandItem.setScore(temp.get(1)); reclist.add(recommandItem); } recommandResponse.setStatus("200"); recommandResponse.setCount(map.get("size")); recommandResponse.setCki(map.get("cki")); recommandResponse.setRecommandlist(reclist); mav.addObject("responseList", recommandResponse); return mav; }