com.demo.mapper패키지에서
인덱스 순으로 Board리스트를 가져오는 메서드 작성
public interface MenuMapper {
@Select("select board_info_idx, board_info_name " + "from board_info_table " + "order by board_info_idx")
List<BoardInfoBean> getMenuList();
}
ServletAppContext
// 쿼리문 실행을 위한 객체
@Bean
public MapperFactoryBean<MenuMapper> getMenuMapper(SqlSessionFactory factory) throws Exception{
MapperFactoryBean<MenuMapper> factoryBean = new MapperFactoryBean<MenuMapper>(MenuMapper.class);
factoryBean.setSqlSessionFactory(factory);
return factoryBean;
}
@Bean
public MapperFactoryBean<BoardMapper> getBoardMapper(SqlSessionFactory factory) throws Exception{
MapperFactoryBean<BoardMapper> factoryBean = new MapperFactoryBean<BoardMapper>(BoardMapper.class);
factoryBean.setSqlSessionFactory(factory);
return factoryBean;
}
서버에서의 처리과정을 크게 3개로 분리
Controller, Service, Repository
@Service
public class MenuService {
@Autowired
private MenuMapper menuMapper;
public List<BoardInfoBean> getMenuList(){
List<BoardInfoBean> menuList = menuMapper.getMenuList();
return menuList;
}
}
서비스 패키지도 컴포넌트 스캔으로 빈 등록
@ComponentScan("com.demo.service") // 스캔 추가