JSP ファイルからスイッチを削除する正しい方法は何ですか? 複数のタイプのオブジェクトを返すことができるファクトリがあります。それぞれに独自の表現ロジックがあるため、次のようなものが必要です。
//From controller
@RequestMapping(value = "/source", method = RequestMethod.POST)
public ModelAndView doMainJob(@RequestParam("text") String text) {
ResultState state = new ResultStateFactory().fromString(text);
ModelAndView model = new ModelAndView("result/view");
model.addObject("state", state);
model.addObject("stateType", state.getClass());
return model;
}
//from jsp/result/view.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="main" tagdir="/WEB-INF/tags" %>
<%@taglib prefix="r" tagdir="/WEB-INF/tags/result" %>
<main:basic_layout>
<jsp:body>
<c:choose>
<c:when test="${stateType == StateA}"><r:stateA param=${state} /></c:when>
<c:when test="${stateType == StateB}"><r:stateB param=${state} /></c:when>
<c:when test="${stateType == StateC}"><r:stateC param=${state} /></c:when>
.
.
.
<c:when test="${stateType == StateX}"><r:stateX param=${state} /></c:when>
<c:when test="${stateType == StateY}"><r:stateY param=${state} /></c:when>
</c:choose>
</jsp:body>
</main:basic_layout>
私のファクトリは注釈に基づいているため、正しい注釈を使用して状態を簡単に追加できます。タグビューに似たようなことをしたいです。2 つのファイルだけを追加するのが理想的です。正しい注釈を含む 1 つの状態と 1 つのタグ ファイルです。