파게로그

[Spring MVC] 데이터 서비스 클래스 본문

콤퓨타 왕기초/Spring

[Spring MVC] 데이터 서비스 클래스

파게 2021. 4. 29. 11:50
public class NoticeService {
    private String url = "jdbc:oracle:thin:@localhost:1521/xepdb1";
    private String uid = "berry";
    private String pwd = "qwer123";
    private String driver = "oracle.jdbc.driver.OracleDriver";
    
    // ...
}

 

public class ListController implements Controller {
	private NoticeService noticeService;
    
    public void setNoticeService(NoticeService noticeService) {
    	this.noticeService = noticeService;
    }
    
    @Override
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) {
    	ModelAndView mv = new ModelAndView("notice.list");
        List<Notice> list = noticeService.getList(1, "TITLE", "");
        mv.addObject("list", list);
        
        return mv;
    }
}

 

dispatcher-servlet.xml

<bean id="/index" class="NoticeController" >
<bean class="com.ddoongi.web.service.NoticeService" />

 

list.jsp

<!-- tag library -->
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!-- items: mv that was returned -->
<c:forEach var="n" items="${list}">
<tr>
	<td>${n.id}</td>
    <!-- ... -->
</tr>
</c:forEach>

 

 

Comments