I'm working on an "absence management" web app using AngularJS and Spring MVC.
In my JSP, i used AngularJS to retrieve a specific students.
I want to select the absent students and add, for each one of them, an absence
instance in the DB.
I have two classes : Student.java
, Absence.java
.
@Entity
@Table(name = "STUDENT")
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID_STUDENT")
private Long idStudent;
@Column(name = "NAME")
private String name;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "idStudent")
private List<Absence> absences = new ArrayList<Absence>();
//getters & setters...
}
@Entity
@Table(name = "ABSENCE")
public class Absence {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID_ABSENCE")
private Long idAbsence;
@Column(name = "ABSENCE_DATE")
private Date absenceDate;
//getters & setters...
}
Here is my JSP :
<form method="post" action="/absences/add">
<table>
<thead>
<tr>
<th>#</th>
<th>Student</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="student in students">
<td>
<input type="checkbox" name="StudentsIds[]" value="{{student.idStudent}}" />
</td>
<td>{{student.name}}</td>
</tr>
</tbody>
</table>
<input type="date" name="absenceDate" />
<input type="submit" value="Submit"/>
</form>
I searched online and tried multiple stuff but nothing seems to work.
Thank you in advance!
EDIT 1:
I tried this in my controller, but i'm having a rough time trying to add multiple absences ...
@RequestMapping(value = "/absences/add", method = RequestMethod.POST)
public String addAbsence(@RequestParam(studentsIds[]) Long [] studentsIds, Absence[] absences) {
//It seems there is a problem with "Absence[] absences" ...
return "listAbsences";
}