使用path属性将boolean值传递给控制器​​的jsp页面

时间:2016-07-26 05:16:25

标签: java jsp spring-mvc

我想知道如何从控制器设置复选框值。请找到我的代码。

控制器

@media(max-width: 900px){
   // you can write your css here 

   .class{
      // write your css property 
   }
}

Student.java

......
......
Student student=service.findRecord(studentID) //received record from DAOImpl 
.....
.....
return "EditStudent";

EditStudent.jsp

 @Entity
 @Table(name = "student_detail")
 public class Student
 {
 @Id 
 @Column(name = "ID")
 @GeneratedValue
 private int ID;
 @Column(name = "studentID")
 private int studentID;
 @Column(name = "studentDescrip")
 private String studentDescrip;
 @Column(name = "status")
 private boolean status;
 .....
 .....getter setter method

我的问题是复选框状态始终设置为true。我在控制器中获取状态值为false,但在jsp页面中未设置状态为false。请更正我的代码...

2 个答案:

答案 0 :(得分:1)

如果您使用的是弹簧标签,则必须使用此

In your controller you have to add an object "student" to the ModelAndView

<form:form model="student">
   <td>
       <!-- Here you access to the status attribute, case sensitive.--> 
       <form:checkbox id="Status" path="status" class="form-control" />
   </td>
...
</form>

答案 1 :(得分:0)

如果你正在使用简单的jsp页面,那么

public interface A
{
    void func();
}
public abstract class B: A
{
    public abstract void func();
}
public class C : B
{
    public override void func()
    {
        throw new NotImplementedException();
    }
}
public class D : B
{
    public override void func()
    {
        throw new NotImplementedException();
    }
}

请注意:在编写此代码之前,您应该编写将获得<tr class="hide convert"> <th>Status</th> <td><form:checkbox name="Status" id="Status" path="<%=student.Status %>" class="form-control" /> </td> </tr> 对象的逻辑。