이 내 스프링 MVC MongoDB를 프로젝트에 내 모델 클래스입니다Mongodb에서 결과의 일부로 반환되는 arrayList를 반복 처리하려면 어떻게해야합니까?
public class SampleProject{
@Id
String id;
public String getId() {
return id;
}
String regNo;
String name;
ArrayList<String> result;
public String getRegNo() {
return regNo;
}
public String getName() {
return name;
}
public ArrayList<String> getResult() {
return result;
}
}
이 내 서비스 클래스는
@Repository("resultService")
public class ResultService {
@Autowired
private MongoTemplate mongoTemplate;
public static final String COLLECTION_NAME = "collectionName";
public StudentResult getStudentResult(String regNo) {
Query query = new Query(Criteria.where("regNo").is(regNo));
StudentResult Ek = mongoTemplate.findOne(query, StudentResult.class);
return Ek;
}
}
이 내 컨트롤러 클래스는
같은 모습입니다 같은 모습입니다public class ResultController {
private final ResultService resultService;
@Autowired
public ResultController(ResultService resultService) {
this.resultService = resultService;
}
@RequestMapping(value ="/search", method = RequestMethod.GET)
public String getStudentResult(String regNo, ModelMap model){
model.addAttribute("studentResult",resultService.getStudentResult(regNo));
return "output";
}
}
내 JSP가
<%@ taglib prefix="c" uri="Oracle Technology Network for Java Developers" %>
<c:out value="${studentResult.name}"/>
<c:out value="${studentResult.regNo}"/>
<c:out value="${studentResult.deptName}"/>
<c:out value="${studentResult.collName}"/>
<c:out value="${studentResult.result}"/> <!--This line prints the arraylist as arraylist.-->
<!--But the following iteration using foreach doesn't work -->
<c:forEach var="student" items="${studentResult}">
<tr>
<td>${student.name}</td>
<td>${student.regNo}</td>
<td><input type="button" value="delete" onclick="window.location='person/delete?id=${person.id}'"/></td>
</tr>
</c:forEach>
과 같은 방법이이 DB이
{ "_id"모습입니다 : ObjectId가 ("53f017f2300469e091855f0d"), "레뇨": "(3103)", " "기술", "deptName": "B. 기술", "결과": [{ "subjCode": "CY6251", "등급": "ABCD", "collName" "E", "결과": "PASS", "subjName": "엔지니어링 화학 -II"}, { "subjCode": "GE6151", "grade": "subjCode": "GE6252", "grade": "D", "result": "PASS", " "subjName": "기본 전기 및 전자 공학"}, { "subjCode": "GE6253", "등급": "E", "결과": "통과", "하위 이름": "엔지니어링 역학"}, ]}
이제 arraylist에서 각 주제 이름과 등급을 표시 할 수 있도록 JSP에서 arraylist를 반복 할 수 있습니까?
나는 내 taglib 선언을 변경했다. 하지만 변경 전과 변경된 후에 JSP는 "알 수없는 태그 (c : forEach)"을 표시합니다. 나는 Stackoverflow에서 대부분의 답변에 따라 해결할 수 없었다.
taglib에 잘못된 uri가 있다고 생각합니다. "Java 개발자를위한 Oracle Technology Network"란 무엇입니까? 대신에 다음을 사용하십시오. <% @ taglib prefix = "c"uri = "http://java.sun.com/jsp/jstl/core"%> – user23123412
다음 오류가 발생합니다. "java .sun.com/jsp/jstl/ 코어 "" – user3705478
jstl 라이브러리를 포함 시켰습니까? 또는 web.xml에서 매핑 했습니까? 자세한 내용은 http://stackoverflow.com/tags/jstl/info를 참조하십시오. – user23123412