DAO方法的标准命名约定 [英] Standard Naming Convention for DAO Methods

查看:456
本文介绍了DAO方法的标准命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如,我看到的一个命名约定是使用 get()返回单个实体,然后 find()返回实体列表。



如果没有一个,你的团队使用的是什么,为什么?

解决方案

通常我的名字这种方法使得该名称提示将由该方法应用的CRUD操作的类型,例如 add * save * find *




  • add * 可以应用于 INSERT 操作,如 addPhoneNumber(Long userId)


  • get * 可以申请 SELECT 操作,如 getEmailAddress(Long userId)


  • set * 可以应用于执行 UPDATE 操作的方法。


  • delete * 可以应用于 DELETE 操作,例如 deleteUser(Long userId) code>。虽然我不太确定物理删除有多有用。就个人而言,我会设置一个标志,表示该行不会被使用,而不是执行物理删除。


  • * 可以应用于检查某些东西的方法,例如 isUsernameAvailable(String username)



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 single entity and find() to return a List of entities.

If there isn't one, what's the one your team is using and why?

解决方案

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).

这篇关于DAO方法的标准命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆