如何使用jsp表

时间:2017-04-04 17:43:48

标签: java database spring-mvc

我有一个带有两个下拉列表的表单,一个用于选择一个组,另一个用于选择一个材料,因此commandName是DTO类,其中包含两个List字段“Group”和“Material”类,我有另一个类“缺席“将ManyToOne映射到班级学生和班级材料,我想列出所选组的学生在所选材料中标记他们的缺席,同时类Absence有一个字符串字段,其中”存在“或”缺席“作为值和一个日期字段,该怎么做? 对此有任何帮助将不胜感激,谢谢

这是DTO课程

public class ListeleveDTO {

 private java.util.List<Groupe> groupe;
    private java.util.List<Matiere> matiere;

    public ListeleveDTO() {

    }

    public ListeleveDTO(java.util.List<Groupe> groupe, java.util.List<Matiere> matiere) {

        this.groupe= groupe;
        this.matiere = matiere;


    }

Class Absence

@Entity
@Table(name = "Absence")
public class Absence implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) 
@Column(name="Date", nullable=false)
private Date date;

@Column(name="Etat", unique=true,nullable=false)
private EtatAbs etat;//enum class which contains "Present" or "Absent"


@ManyToOne
@JoinColumn(name="Eleve_id", referencedColumnName="id")
private  Eleve eleve;


@ManyToOne
@JoinColumn(name="Matiere_id", referencedColumnName="id")
private Matiere matiere;
//getters and setters

jsp表格

 <form:form method="post"  commandName="listeleveDTO" role="form" >

                         <label>Sélectionnez un groupe</label>
                         <select name="Groupe" class="form-control">

                         <option value="NONE" label="--- Select ---" />    


                         <c:forEach items="${listeleveDTO.groupe}" var="m">

                         <option value="${m.libelle}">${m.libelle} </option>                 

                         </c:forEach>

                         </select>



                         <div class="form-group"  style="margin-top:50px">    

                         <label> Sélectionnez une matiere</label>
                         <select name="Matiere" class="form-control">

                         <option value="NONE" label="--- Select ---" />    


                         <c:forEach items="${listeleveDTO.matiere}" var="mg">

                         <option value="${mg.libelle}">${mg.libelle} </option>                 

                         </c:forEach>

                         </select>

                                    </div>               
                     <button type="submit" class="btn btn-info" style="margin-top:30px" >Valider</button>

                                </form:form>

控制器

@Controller
@RequestMapping ("abs")

@SessionAttributes({"groupe","matiere"})

public class AbsController {


@Autowired GroupeService groupeservice;

@Autowired AbsenceService absenceService;
    @Autowired MatiereService matiereservice;



@RequestMapping(method = RequestMethod.GET)
public ModelAndView showForm() {
    ModelAndView mv = new ModelAndView("abs");

    ListeleveDTO listeleveDTO = new ListeleveDTO(groupeservice.findAllGroupes(), matiereservice.findAlmatieres());
    mv.addObject("listeleveDTO",listeleveDTO );

    return mv;
}

@RequestMapping( method = RequestMethod.POST)
public String submitForm( @ModelAttribute("listeleveDTO") ListeleveDTO listeleveDTO,BindingResult result,
        ModelMap map

         ) {

    return "listeleve" ;
}

@RequestMapping(value="/listeleve")
public String geteleves (Model model){

    model.addAttribute("absence", new Absence());
    model.addAttribute("listAbsence", absenceService.findAllAbsence());
    model.addAttribute("etats",EtatAbs.values());
    return "listeleve";

}

ListofStudent jsp

<table class="table table-striped table-bordered table-hover">
                                <thead>
                                    <tr>  
                                        <th width="200px">Eleve</th>
                                        <th width="150px">Absence</th>

                                         <th width="150px">Edit</th>                     
                                    </tr>
                                </thead>
                                <tbody>

                                <sql:query dataSource="${ds}" var="result">
                   SELECT X.FIRST_NAME,X.LAST_NAME,A.Etat,X.id from Absence A, MATIERE M,
                  (SELECT E.id,E.FIRST_NAME,E.LAST_NAME from GROUPE G, ELEVE E where G.LIBELLE= "<%=liste %>" and E.groupe_id = G.id) as X
                   where X.id = A.ELEVE_ID and A.MATIERE_ID = M.id and M.LIBELLE = "<%=liste1%>" ;
                                 </sql:query>


//i joined table groupe and eleve(student) to select first and last name of students then i joined table absence to table matiere (material) and table X the result of joining student and group to select field "etat",this field contains "absent" or "present" student


                                   <c:forEach var="row" items="${result.rows}">  
                                   <tr  class="gradeU">

                                   <td><c:out value="${row.FIRST_NAME}"/> <c:out value="${row.LAST_NAME}"/></td>

                                   <td>                   
                                   <c:out value="${row.Etat}"/>
                                   </td>

                                   <td><a href="update.jsp?id=<c:out value="${row.id}"/>"></a></td>
                                   </tr>
                                   </c:forEach>             
                                </tbody>
                            </table>

0 个答案:

没有答案