api - Java 开发 App 接口中关于 url 和入参名称规范的问题
PHP中文网
PHP中文网 2017-04-18 10:48:21
0
5
903

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

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

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

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

PHP中文网
PHP中文网

认证0级讲师

reply all(5)
伊谢尔伦

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

黄舟

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.

左手右手慢动作

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

刘奇

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.

小葫芦

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template