开发者

Recommended alternative to abusing UserDetailServiceImpl for non-user-related database lookups?

In the project I am working with, there is a UserDetailServiceImpl class which carries out all of the user-related database lookups.

The problem is, I have gotten into the bad habit of doing non-user-related database lookups there too and using the UserDetailServiceImpl class as a default lookup service to avoid doing database lookups directly in the controller action methods. The advantage of this is that I don'开发者_Python百科t have to create a separate lookup service for each of my models - which would seem rather silly and redundant. But is there a more standard approach to database lookups that I should consider to avoid angering the Spring gods?


I don't like using services just to wrap database lookups, you end up with all of the business logic in your controller. I would organize my services so there would be one per type of user. So if I had customers and data-entry people and admins, I would make a customerService and a dataEntryService and an adminService. Each service would expose the methods that that kind of customer needs. No business logic should be in a controller, it is strictly concerned with getting inputs from the url and request and the session, calling a method on some service (passing in those inputs), then taking the result of the service call and putting that where the page can display it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜