Multiple requestmapping value with path variables

前端 未结 4 1883
北海茫月
北海茫月 2021-02-03 10:08
@RequestMapping(value = {\"/abcd\", \"/employees/{value}/{id}\"})
public String getEmployees(
      @PathVariable(value = \"value\") String val, 
      @PathVariable(val         


        
4条回答
  •  一向
    一向 (楼主)
    2021-02-03 10:48

    I had a similar problem and I found this solution:

    @GetMapping(value = {"/clients/page", "/clients/page/{page}"})
    public Page index(@PathVariable Optional page) {
       PageRequest pageRequest = page.map(integer -> PageRequest.of(integer, 4))
       .orElseGet(() -> PageRequest.of(0, 4));
          return clientService.showAll(pageRequest);
    }
    

    Intellij helped me to get this kind of compact result. Although Intellij throw this message:

    ''Reports any uses of java.util.Optional, java.util.OptionalDouble, java.util.OptionalInt, java.util.OptionalLong or com.google.common.base.Optional as the type for a field or a parameter. Optional was designed to provide a limited mechanism for library method return types where there needed to be a clear way to represent "no result". Using a field with type java.util.Optional is also problematic if the class needs to be Serializable, which java.util.Optional is not. ''

    To be honest, I'm new in this business and I don't understand clearly what the IDE is telling me. If someone with more expertise could help to clarify that message would be great.

提交回复
热议问题