@RequestMapping(value={"/list/{filters}","/list/{filters}/"},method = RequestMethod.GET) @SiteTitle("{navigation.user.list}") public ModelAndView filterList(@MatrixVariable(pathVar = "filters") Map<String,List<String>> filters) { ModelMap mm = new ModelMap(); if(filters.containsKey("role_name")) { mm.addAttribute("userList", userService.getUsersByRole(userRoleService.getUserRoleByName(filters.get("role_name").get(0)))); } else { mm.addAttribute("userList", userService.getAllUsers()); } return new ModelAndView("user_list",mm); }
@RequestMapping(value = {"/list/{filters}","/list/{filters}/"},method = RequestMethod.GET) @SiteTitle("{navigation.program.list}") public ModelAndView filterList(@MatrixVariable(pathVar = "filters") Map<String,List<String>> filters) { ModelMap mm = new ModelMap(); if(filters.containsKey("name") && filters.containsKey("version")) { mm.addAttribute("programList", programService.getProgramByNameAndVersion(filters.get("name").get(0), filters.get("version").get(0))); } else { mm.addAttribute("programList", programService.getAllPrograms()); } return new ModelAndView("program_list",mm); }
@RequestMapping(value = {"/list/{filters}","/list/{filters}/"},method = RequestMethod.GET) public ModelAndView filterList(@MatrixVariable(pathVar = "filters") Map<String,List<String>> filters, @ModelAttribute("pagination") Pagination pagination) { ModelMap mm = new ModelMap(); if(filters.containsKey("apprun")) { ApplicationRun applicationRun = applicationRunService.getApplicationRunByID(Long.valueOf(filters.get("apprun").get(0))); SearchResponse<CanonicOutput> result = canonicOutputService.getCanonicOutputByAppRun(applicationRun, pagination); pagination.setNumberOfRecords(result.getTotalResultSize()); mm.addAttribute("pagination", pagination); mm.addAttribute("outputList", result.getResults()); } else { mm.addAttribute("outputList", ListUtils.EMPTY_LIST); } return new ModelAndView("canonicoutput_list",mm); }
@Override public boolean supportsParameter(MethodParameter parameter) { MatrixVariable matrixVariable = parameter.getParameterAnnotation(MatrixVariable.class); if (matrixVariable != null) { if (Map.class.isAssignableFrom(parameter.getParameterType())) { return !StringUtils.hasText(matrixVariable.name()); } } return false; }
@Override public boolean supportsParameter(MethodParameter parameter) { if (!parameter.hasParameterAnnotation(MatrixVariable.class)) { return false; } if (Map.class.isAssignableFrom(parameter.getParameterType())) { String variableName = parameter.getParameterAnnotation(MatrixVariable.class).name(); return StringUtils.hasText(variableName); } return true; }
@RequestMapping("/{root}") public void handle(@PathVariable("root") int root, @MatrixVariable(required=false, defaultValue="7") int q, Writer writer) throws IOException { assertEquals("Invalid path variable value", 42, root); writer.write("test-" + root + "-" + q); }
@RequestMapping("/hotels/{hotel}/bookings/{booking}-{other}") public void handle(@PathVariable("hotel") String hotel, @PathVariable int booking, @PathVariable String other, @MatrixVariable(name = "q", pathVar = "hotel") int qHotel, @MatrixVariable(name = "q", pathVar = "other") int qOther, Writer writer) throws IOException { assertEquals("Invalid path variable value", "42", hotel); assertEquals("Invalid path variable value", 21, booking); writer.write("test-" + hotel + "-q" + qHotel + "-" + booking + "-" + other + "-q" + qOther); }
@RequestMapping("/hotels/{hotel}/bookings/{booking}-{other}") public void handle(@PathVariable("hotel") String hotel, @PathVariable int booking, @PathVariable String other, @MatrixVariable MultiValueMap<String, String> params) { assertEquals("Invalid path variable value", "42", hotel); assertEquals("Invalid path variable value", 21, booking); assertEquals(Arrays.asList("1", "2", "3"), params.get("q")); assertEquals("R", params.getFirst("r")); }
@RequestMapping("/{root:\\d+}{params}") public void handle(@PathVariable("root") int root, @PathVariable("params") String paramString, @MatrixVariable List<Integer> q, Writer writer) throws IOException { assertEquals("Invalid path variable value", 42, root); writer.write("test-" + root + "-" + paramString + "-" + q); }
public void handle( String stringArg, @MatrixVariable Map<String, String> map, @MatrixVariable MultiValueMap<String, String> multivalueMap, @MatrixVariable(pathVar="cars") MultiValueMap<String, String> mapForPathVar, @MatrixVariable("name") Map<String, String> mapWithName) { }
@RequestMapping(value = "/{id:\\d+}", method = RequestMethod.GET) public ResponseEntity<?> getResourceById(@PathVariable("id") K id, @MatrixVariable Optional<Map<String, String>> maps) { log.info("+++ getResourceById {}", id); T item = service.findById(id); //if(maps.isPresent()){ log.info("+++++ id={} , matrixVars={} ", id, maps); // } return getRightResponseEntity(item); }
@RequestMapping( value = "{path}/invoice", method = RequestMethod.POST ) @ResponseBody public HttpEntity invoice( @PathVariable String path, @MatrixVariable(value = "refNo", pathVar = "path") String referenceNumber, @RequestParam(value = "image", required = true) List<MultipartFile> files ) throws IOException { System.out.println(path); System.out.println(files); return ResponseEntity.ok("{\"state\": \"All Well\"}"); }
/** * URL template pattern -- Work with matrix * GET /teacher/1018110323;name=lihe;age=18 * @param day * @param model * @return */ @RequestMapping(value="/teacher/{userId}", method = RequestMethod.GET) public String matrix(@PathVariable String userId , @MatrixVariable(value="name",defaultValue="joe") String theName , @MatrixVariable int age, Model model) { model.addAttribute("username",theName); model.addAttribute("age",age); return "main"; }
/** * URL template pattern -- Work with matrix -- advanced * matrix can also be obtained in a map. * * GET /teacher/1018110323;name=lihe/18;fakeAge=25 * @param day * @param model * @return */ @RequestMapping(value="/teacher/{userId}/{age}", method = RequestMethod.GET) public String matrixAdvanced(@PathVariable String userId , @PathVariable int age , @MatrixVariable(value="name", pathVar="userId") String theName , @MatrixVariable(pathVar="age") int fakeAge, Model model) { model.addAttribute("username",theName); model.addAttribute("age",fakeAge); return "main"; }
public boolean supportsParameter(MethodParameter parameter) { MatrixVariable paramAnnot = parameter.getParameterAnnotation(MatrixVariable.class); if (paramAnnot != null) { if (Map.class.isAssignableFrom(parameter.getParameterType())) { return !StringUtils.hasText(paramAnnot.value()); } } return false; }
public boolean supportsParameter(MethodParameter parameter) { if (!parameter.hasParameterAnnotation(MatrixVariable.class)) { return false; } if (Map.class.isAssignableFrom(parameter.getParameterType())) { String paramName = parameter.getParameterAnnotation(MatrixVariable.class).value(); return StringUtils.hasText(paramName); } return true; }
@RequestMapping("/hotels/{hotel}/bookings/{booking}-{other}") public void handle(@PathVariable("hotel") String hotel, @PathVariable int booking, @PathVariable String other, @MatrixVariable(value="q", pathVar="hotel") int qHotel, @MatrixVariable(value="q", pathVar="other") int qOther, Writer writer) throws IOException { assertEquals("Invalid path variable value", "42", hotel); assertEquals("Invalid path variable value", 21, booking); writer.write("test-" + hotel + "-q" + qHotel + "-" + booking + "-" + other + "-q" + qOther); }
@RequestMapping("/matrix/{name}/{another}") public String matrix(@PathVariable("name") String name, @MatrixVariable(value = "p", pathVar = "name") int p, @MatrixVariable(value = "q", pathVar = "name") int q, @PathVariable("another") String another, @MatrixVariable(value = "x", pathVar = "another") int x) { return name + "=" + p + "-" + q + ";" + another + "=" + x; }
@Override protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { MatrixVariable annotation = parameter.getParameterAnnotation(MatrixVariable.class); return new MatrixVariableNamedValueInfo(annotation); }
@Override protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception { @SuppressWarnings("unchecked") Map<String, MultiValueMap<String, String>> pathParameters = (Map<String, MultiValueMap<String, String>>) request.getAttribute( HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST); if (CollectionUtils.isEmpty(pathParameters)) { return null; } String pathVar = parameter.getParameterAnnotation(MatrixVariable.class).pathVar(); List<String> paramValues = null; if (!pathVar.equals(ValueConstants.DEFAULT_NONE)) { if (pathParameters.containsKey(pathVar)) { paramValues = pathParameters.get(pathVar).get(name); } } else { boolean found = false; paramValues = new ArrayList<String>(); for (MultiValueMap<String, String> params : pathParameters.values()) { if (params.containsKey(name)) { if (found) { String paramType = parameter.getParameterType().getName(); throw new ServletRequestBindingException( "Found more than one match for URI path parameter '" + name + "' for parameter type [" + paramType + "]. Use pathVar attribute to disambiguate."); } paramValues.addAll(params.get(name)); found = true; } } } if (CollectionUtils.isEmpty(paramValues)) { return null; } else if (paramValues.size() == 1) { return paramValues.get(0); } else { return paramValues; } }
private MatrixVariableNamedValueInfo(MatrixVariable annotation) { super(annotation.name(), annotation.required(), annotation.defaultValue()); }
public void handle( String stringArg, @MatrixVariable List<String> colors, @MatrixVariable(name = "year", pathVar = "cars", required = false, defaultValue = "2013") int preferredYear) { }
@RequestMapping("/filter/{ByCriteria}") public String getProductsByFilter(@MatrixVariable(pathVar = "ByCriteria") Map<String, List<String>> filterParams, Model model) { model.addAttribute("products", productService.getProductsByFilter(filterParams)); return "products"; }
@Override protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { MatrixVariable annotation = parameter.getParameterAnnotation(MatrixVariable.class); return new PathParamNamedValueInfo(annotation); }
private PathParamNamedValueInfo(MatrixVariable annotation) { super(annotation.value(), annotation.required(), annotation.defaultValue()); }
public void handle( String stringArg, @MatrixVariable List<String> colors, @MatrixVariable(value="year", pathVar="cars", required=false, defaultValue="2013") int preferredYear) { }
@RequestMapping("/filter/{ByCriteria}") public String getProductsByFilter(@MatrixVariable(pathVar="ByCriteria") Map<String,List<String>> filterParams, Model model) { model.addAttribute("products", productService.getProductsByFilter(filterParams)); return "products"; }