Home  >  Q&A  >  body text

api - Java 开发 App 接口中关于 url 和入参名称规范的问题

现在公司用开发给前端用的接口,语言是Java,现在想定开发规范,然后有些纠结的地方:

一个是接口的名称,之前用的的驼峰的形式,比如myTopic,但是看网上推荐的有my_topic,更容易辨识,或者推荐比较多的my-topic,看到说法是比前一种输入起来更方便。

还有个入参的问题,比如一个接口接受的参数是分页的页数,之前也是习惯性的驼峰的pageNum,但看很多公司,比如支付宝的接受参数都是page_num这种。

想问下大家以上两个问题一般用的是那种或推荐哪种?

PHP中文网PHP中文网2744 days ago864

reply all(5)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:50:21

    Each company has different writing methods, and even different teams within a company will have different writing methods.

    But there is always a way of writing that is correct most of the time, and that is the hump.

    The camel case writing method has also been verified by experiments. It is the easiest to recognize and the recognition speed is fast. You can read the study on camelback readability here

    reply
    0
  • 黄舟

    黄舟2017-04-18 10:50:21

    Personally, I think the so-called specification is the agreement between your front-end and backend. Once the agreement is made and it can meet the needs, then this agreement is your specification.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 10:50:21

    The first one
    https://img.hacpai.com/file/2...

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 10:50:21

    There is no standard answer to the style question. Cases can be found in the 3 methods you listed.

    I personally use the underline method page_num, which is more readable and uses lowercase letters, which is more suitable for url/uri.

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 10:50:21

    It is recommended to use Douban’s URL design http://www.prower.cn/interact...

    reply
    0
  • Cancelreply