'How do I defining a bean type of this Mapper class?
I want to know how can I register this Mapper class as a Spring bean. An entity called NormalBoard was designed, and an entity called ContestBoard that inherited it was designed and even Service Layer was created.
public class Mapper {
private MenuRepository menuRepository;
private ContestBoardServiceImpl contestBoardService;
private NormalBoardServiceImpl normalBoardService;
public BoardService findBoardServiceByMenuId(Integer menuId){
MenuType menuType = menuRepository.findMenuTypeByMenuId(menuId).get();
switch(menuType){
case CONTEST:
return contestBoardService;
default:
return normalBoardService;
}
}
I tried to search the menu according to the menuId value coming in requestParam from one controller and call the service layer method corresponding to the menu.
public class BoardController{
private final Mapper mapper;
@GetMapping
public Page<Object> getBoardList(Pageable pageable, @RequestParam Integer menuId ) {
return mapper.findBoardServiceByMenuId(menuId).getBoardList(menuId, pageable);
}
}
This may be a silly way, but I came up with it because I don't want to design duplicate Controllers about NormalBoardController and ContestBoardController.
In this case, if you want to register Spring Bean for this Mapper class, what kind of annotation should be attached?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
