0
我有一个包含一个布尔属性Spring MVC和JSP - 映射布尔分为模型
class A {
Boolean marked;
[here getter and setter]
}
在我的JSP页面的I类复选框连接到模型属性:
<form:form method="POST" action="updateA" modelAttribute="myAInstance">
<form:checkbox path="marked"/>Valid<br>
<input type="submit" value="Save"/>
</form:form>
...
<span>From the DB: ${myAInstanceFromDB} </span> // this displayes true
提交当Controller
得到正确的值(myAInstance
),并将其保存在DB
中。但是,如果我重新加载页面(myAInstanceFromDB
),我以前选择并保存的checkbox
未被选中。我想这是因为复选框的路径指向modellattribute
要发布到server
而不是database
对象我过去的页面。加载页面时如何标记复选框?
什么是你在DB被保存价值? – Jobin
我使用MySQL和休眠。 java类中的属性是布尔值,DB列的类型是位(1)。使用MySQL Workbench当我执行一个select时,我看到1(真)。 –
下面是一些答案: http://stackoverflow.com/questions/7845741/setting-jsp-checkbox-with-a-value-from-database http://stackoverflow.com/questions/5052003/how -to-set-checked-checkbox-based-on-database-record – KayV