From 89c9994f0f1b53699068bc075f547ea75b50d65c Mon Sep 17 00:00:00 2001 From: mjkhan21 Date: Mon, 27 Nov 2023 15:59:37 +0900 Subject: [PATCH] =?UTF-8?q?setPagingInfo(...)=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../foundation/web/AbstractController.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/main/java/cokr/xit/foundation/web/AbstractController.java b/src/main/java/cokr/xit/foundation/web/AbstractController.java index ba2abdc..d6097de 100644 --- a/src/main/java/cokr/xit/foundation/web/AbstractController.java +++ b/src/main/java/cokr/xit/foundation/web/AbstractController.java @@ -5,6 +5,7 @@ import java.io.FileInputStream; import java.io.InputStream; import java.net.URLEncoder; import java.util.Collection; +import java.util.Map; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; @@ -141,6 +142,44 @@ public abstract class AbstractController extends AbstractComponent { .addObject(prefix + "Total", bounded.getTotalSize()); } + /**ModelAndView에 list와 페이징 정보를 설정한다.
+ * 예를 들어 setPagingInfo(mav, list, "prefix")와 같이 호출하면 + * mav에 다음과 같이 설정한다. + *
{
+	 *     "prefixList": list,
+	 *     "prefixPagingInfo": {
+	 *         "start": list.getStart(),
+	 *         "fetchSize": list.getFetchSize(),
+	 *         "totalSize": list.getTotalSize()
+	 *     }
+	 * }
+ * @param mav ModelAndView + * @param collection Collection + * @param prefix 접두어 + * @return ModelAndView + */ + protected ModelAndView setPagingInfo(ModelAndView mav, Collection collection, String prefix) { + if (collection instanceof BoundedList) { + BoundedList bounded = (BoundedList)collection; + Map map = Map.of( + "start", bounded.getStart(), + "totalSize", bounded.getTotalSize(), + "fetchSize", bounded.getFetchSize() + ); + mav.addObject(prefix + "List", bounded) + .addObject(prefix + "PagingInfo", map); + } else { + Map map = Map.of( + "start", 0, + "totalSize", collection.size(), + "fetchSize", collection.size() + ); + mav.addObject(prefix + "List", collection) + .addObject(prefix + "PagingInfo", map); + } + return mav; + } + /**한 번에 반환할 조회 결과의 수를 설정한다.
*
  • fetchAll이 true이면 모든 조회 결과 반환
  • *
  • 그렇지 않으면