亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

問個Java 遇見數據庫時的對象設計問題

問個Java 遇見數據庫時的對象設計問題

元芳怎么了 2019-04-16 20:26:52
用的springmvc+mybatis3框架,假設有用戶與角色兩張表,以及一張關聯表,分別對應的實體user、role和user_role.在service層,為這2個對象分別建立IUserService,IRoleService。我想問的是:需要為中間表建對象user_role嗎?如果建了user_role,需要建IUserRoleService嗎?中間表的關系維護職責應該放哪個service,如刪除用戶同時需刪除與角色的關系,刪除角色,需刪除與用戶的關系等等。。多謝指點!
查看完整描述

1 回答

?
四季花海

TA貢獻1811條經驗 獲得超5個贊

完全不需要,數據庫設計不一定要和Java對象設計一致,在你的user對象里面包含role,或者role對象包含user就可以了。
補充:
publicclassUserService{
@Autowired
privateUserRepositoryuserRepository;
@Autowired
privateUserRoleRepositoryuserRoleRepository;
publicvoiddeleteUser(Useruser){
userRepository.delete(user);
userRoleRepository.deleteRoles(user);
}
}
publicclassRoleService{
@Autowired
privateRoleRepositoryroleRepository;
@Autowired
privateUserRoleRepositoryuserRoleRepository;
publicvoiddeleteRole(Rolerole){
roleRepository.delete(role);
userRoleRepository.deleteUsers(role);
}
}
                            
查看完整回答
反對 回復 2019-04-16
  • 1 回答
  • 0 關注
  • 363 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號