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