1、前端请求的路径不要使用-连接,可以使用/进行区分
例:
/v1/account-advance-setting
/v1/accounts/advanced
2、修改请求使用 PutMapping,不要使用Post
例:
@PostMapping("/updateInfo")
@PutMapping()
3、依赖注入统一使用构造方法注入,不要使用set注入
4、对于0这个魔法变量,使用框架已经定义好的常量表示
aseConstants.DEFAULT_TENANT_ID
5、@GetMapping中的请求路径应该见名知意,不应该有歧义
例: 查询账户code是否重复
@GetMapping("/code") 会第一眼认为是根据code查询数据
@GetMapping("/check-code")
6、对于租户organizationId,在路径中可以这么写,但是我们接受时不适用organizationId,而是使用tenantId
@PathVariable(name = "organizationId") Long organizationId
@PathVariable(name = "organizationId") Long tenantId
7、对于日期的类型,不要使用Date类型,使用localDate
private Date startDate;
private LocalDate startDate;
8、表示是否的字段,不要使用isxx命名,使用flag
isDefault
defaultFlag
9、mapper 不能在 service中引用, mapper只能在仓储层(Repository)中被使用
10、当调用实体类的set方法时,将set方法在实体类中封装成一个方法,直接调用方法来调用set方法
heisAccount.setAppSecret(null);
heisAccount.clearSecret();
11、两个事务之间的互相调用,会导致被调用者的事务失效,因为事务是动态代理,要使用动态代理去调用另外一个事务
12、判断某个集合是否为空,不要使用它的isEmpty(),很可能报NP,应该使用提供的工具类
selectDefaultAccountList.isEmpty()
CollectionUtils.isEmpty(selectDefaultAccountList)
13、仓储层不能写业务逻辑
14、租户和用户表的跨库查询,框架有数据权限处理,不需要增加数据库的前缀