Standard Naming Convention for DAO Methods

后端 未结 2 796
后悔当初
后悔当初 2020-12-30 08:53

Is there a standard naming convention for DAO methods, similar to JavaBeans?

For example, one naming convention I\'ve seen is to use get() to return a s

2条回答
  •  星月不相逢
    2020-12-30 09:13

    Usually I name the methods in such way that the name hints the type of the CRUD operation that will be applied by the method, like add*, save* or find*.

    • add* can be applied on INSERT operations, like addPhoneNumber(Long userId).

    • get* can be applied for SELECT operations, like getEmailAddress(Long userId).

    • set* can be applied on method that performs an UPDATE operation.

    • delete* can be applied on DELETE operations, like deleteUser(Long userId). Althought I'm not pretty sure how useful is the physical delete. Personally, I would set a flag that denotes that the row is not gonna be used, rather than performing a physical delete.

    • is* can be applied on a method that check something, for example isUsernameAvailable(String username).

提交回复
热议问题