I am beginner to mongodb and spring mvc.I have created a collection in mongodb.finally i got that collection in my controller.now I want to know how to pass that collection values to my jsp page.
Model: Student.java
@Document(collection = "Studentlist")
public class Student {
private String studentID;
private String studentName;
public void setcustomerID(String studentID) {
this.studentID = studentID;
}
public String getstudentID() {
return studentID;
}
public void setcustomerName(String studentName) {
this.studentName = studentName;
}
public String getstudentName() {
return studentName;
}
}
homecontroller.java
@RequestMapping(value = "/student", method = RequestMethod.GET)
@ResponseBody
public List<Student> getStudentList() throws Exception {
List<Student> studentList = StudentBO.findAllstudentList();
return studentList;
}
home.jsp
<label for="CustomerName">Customer</label>
<select class="form-control">
<option>student id value from db</option>
<option>student name value from db</option>
How to pass the student name and id values to my dropdown?
In the controller, you can add the model attribute with the map or list values like this:
model.addAttribute("studentList ", studentList );
In the JSP file, you can do the following:
<c:forEach items="${studentList}" var="record">
<td><c:out value="${record.studentID}" /></td>
<td><c:out value="${record.studentName}" /></td>
</c:forEach>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With