(2017) 사이드 프로젝트/fnl-project(게시판)

13. 최신 공지사항 글이 메인 상단에 출력 : ajax

호 두 2017. 6. 5. 11:05
반응형


설명 :  notice 게시판의 최신글이, main 페이지 상단에 노출(웹사이트의 슬라이드바처럼 구현 할 예정이고, 이벤트와 공지사항의 제목과 이미지가 슬라이드바를 통해 직관성있게 사용자에게 출력될 예정, 클릭 시 notice detail로 이동)


참고 :  

http://hompylove.com/system/bbs/board.php?bo_table=tip&wr_id=22 
json 
java collection 

------------------------------------------------------------ 


내코드 :  


menu/menuList.jsp








MenubarUtils(controller)
@Controller
@RequestMapping("menu")
public class MenubarUtils {
	Logger log = Logger.getLogger(this.getClass());

	@Autowired
	private NoticeService noticeService;
	
	// ajax로 최신 공지사항이 출력되는 기능
	@RequestMapping(value="/brandnewNotice.do", method = RequestMethod.GET)
	public @ResponseBody Map<string, object=""> brandnewNotice(Notice notice, Model model) throws Exception{
		
		List<notice> nlist = noticeService.brandnewNotice(notice);
		
		Map<string, object=""> map = new HashMap<string, object="">(); 
		
		System.out.println(nlist);
		
		String ntitle = nlist.get(0).getNotice_title();
		String nContents = nlist.get(0).getNotice_contents();
		String nDate = (nlist.get(0).getNotice_date()).toString();
		
		System.out.println(ntitle);
		System.out.println(nContents);
		System.out.println(nDate);
		
		map.put("ntitle", ntitle);
		map.put("nContents", nContents);
		map.put("nDate", nDate);
		System.out.println(map);
		
		return map;
	}

}




Noticeservice
public interface NoticeService {
	List<notice> brandnewNotice(Notice notice);
}




NoticeserviceImpl
@Service("noticeService")
public class NoticeServiceImpl implements NoticeService{
	Logger log = Logger.getLogger(this.getClass());

	@Autowired
	NoticeDao noticeDao;

	@Override
	public List<notice> brandnewNotice(Notice notice) {
		return noticeDao.brandnewNotice(notice);
	}
}




NoticeDao
@Repository("noticeDao")
public class NoticeDao {
	Logger log = Logger.getLogger(this.getClass());
	
	@Autowired
	private SqlSessionTemplate sqlSession;
	
	public NoticeDao(){}

	public List<notice> brandnewNotice(Notice notice) {
		return (List<notice>) sqlSession.selectList("brandnewNotice", notice);
	}
}




notice-mapper.xml




	
		
		
		
		
		
		
		
		
	

        





반응형