Hi, how are you?
This is how you create a class objectYo
MyObject object = new MyObject();
I'm studying jsp code review If there's MyObject at the front and MyObject at the back of the new, Your type? I don't know how to interpret this difference.
For example,
Action action = new BoardListAction();
Like this code. For your information, action is the interface.
package action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import vo.ActionForward;
public interface Action {
ActionForward execute(HttpServletRequest request, HttpServletResponse response) throws Exception;
}
package action;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import svc.BoardListService;
import vo.ActionForward;
import vo.BoardBean;
import vo.PageInfo;
public class BoardListAction implements Action{
@Override
public ActionForward execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
// // TODO Auto-generated method stub
ArrayList<BoardBean> articleList = new ArrayList<>(); // The part that creates the ArrayList object to store the entire list of articles to be output per page.
int page=1;
int limit = 10; // It is the part where the number of sentences to be output per page is set to 10.
if(request.getParameter("page") != null) {
page=Integer.parseInt(request.getParameter("page"); //The part that changes the value of the page variable when a page to be output in the list view is sent to the parameter.
// In the list view page, click the page number you want to view, and if requested, the page number is sent to the pyrometer.
}
BoardListService boardListService = new BoardListService();
intlistCount = boardListService.getListCount(); // The part that calls the method that returns the total number of statements.
//with total list count
articleList = boardListService.getArticleList(page,limit);
//List Received
//Total number of pages
int maxPage=(int)((double)listCount/limit+0.95); // Add 0.95 to raise★★★★★★★
//The number of start pages to show on the current page (1,11,21, etc.) ★★★★★★★★★★
int startPage = (((int)((double)page/10 + 0.9)) -1) * 10 + 1;
//The number of last pages to show on the current page. (10,20, 30, etc.) ★★★★★★★★★★★★★★★
int endPage = startPage+10-1;
if(endPage > maxPage) endPage=maxPage;
PageInfo pageInfo = new PageInfo();
pageInfo.setEndPage(endPage);
pageInfo.setListCount(listCount);
pageInfo.setMaxPage(maxPage);
pageInfo.setPage(page);
pageInfo.setStartPage(startPage);
request.setAttribute("pageInfo", pageInfo);
request.setAttribute("articleList", articleList);
ActionForward forward = new ActionForward();
forward.setPath("/board/qna_board_list.jsp");
return forward;
}
}
BoardListAction is a type of Action.
BoardListAction can be substituted as an Action because it is a type of Action.
Person = new Min Dong Hyun.
Please think deeply about the aspect of polymorphism in object orientation.
The explanation in the book won't touch much.
The best way to learn is to study design patterns, create simple frameworks, or analyze the frameworks used in the sources above.
The source of the question above appears to be a command pattern. There will be an Executor within the framework that processes the Action.
© 2024 OneMinuteCode. All rights reserved.