Several methods at the dao level

I am currently planning to reorganize an old codebase written in spring + hibernate.

I have seen so many methods in a dao layer that solves the same goal as.

for example, I have a user_info table

there are as many methods in dao-layer as

 getUserInfoById(String userId);
 getUserInfoByName(String name);
 getUserInfoByIdAndName(String userId,String name) 

and the list goes on.

I know this is a very bad practice.

I thought that a solution like I will have only one getUserInfo (User user) method inside this method I will encapsulate the construction of the request, for example

query.with(user.username).with(user.userId)...

I don't know if this is right to follow ...

any suggestions? Any links to pages that explain this concept from the simplest things are also welcome.

+4
source share
1

spring -jpa integration

, , - . spring DAO , . . spring jpa . - , DAO.

:

@Repository

public interface UserRepository extends PagingAndSortingRepository<UserCore, Serializable>, JpaSpecificationExecutor<UserCore>  {

}

java DAO,

, .

+1

Source: https://habr.com/ru/post/1653278/


All Articles