@Path批注中的路径参数,更好

时间:2018-12-15 10:22:48

标签: java rest path jax-rs query-parameters

我的简单问题。

情况:需要编写类似ID的端点

  1. 仅静态TYPE@Path("{" + ID + "}/{" + TYPE "}") public void doSth(@PathParam(ID) String Id, @PathParam(TYPE) String type) {}

    PATH_XXX
  2. 静态static final String PATH_ID = "{" + ID + "}"; static final String PATH_TYPE = "{" + TYPE + "}"; @Path(PATH_ID + SLASH + PATH_TYPE) public void doSth(@PathParam(ID) String Id, @PathParam(TYPE) String type) {}

    func chooseStepFunction(backward: Bool) -> (Int) -> Int {
    func stepForward(input: Int) -> Int { return input + 1 }
    func stepBackward(input: Int) -> Int { return input - 1 }
    return backward ? stepBackward : stepForward
    }
    

你们怎么看,哪个更好用?

1 个答案:

答案 0 :(得分:1)

我愿意

@Path("{id}/{type}")
public void doSth(@PathParam("id") String id, @PathParam("type") String type) {}
  • 它遵守Java命名约定
  • 它比您拥有的更具可读性
  • 比您拥有的要短
  • IDE,然后框架和/或您的测试将告诉您,如果您碰巧在其中一个字符串中打错了字,那肯定是错的。
相关问题