我需要顯示從數據庫中提取的值,這些值是使用spring form:input標籤存儲在數組列表中的。但是我發現'value'屬性不被支持。請幫忙!如何在彈簧中顯示從數據庫獲取的值<form:input>?
0
A
回答
1
我想你會期待這樣的事情。
//假設你有你的類
public class Students{
private String name;
private List<String> Departments;
/* getters/setters */
}
在HTML將是以下。
<form:input path="departments[0]" />
<form:input path="departments[1]" />
有關點擊更多詳情http://www.javacodegeeks.com/2013/07/spring-mvc-form-handling-vol-5-select-option-options-tags.html
1
請首先檢索從DATEBASE列表中,並設置在控制器中的模型屬性列表中看到的例子設置
@Controller
public class UserController {
@RequestMapping(method = RequestMethod.GET)
public String userHome(Model model, EventBean event, UserService userService,ImageBean image)
{
List<Event> events = userService.viewNews(); //retrieve the list from datebase
model.addAttribute("event", event); //add bean object
model.addAttribute("events", events); //add list in model attribute
return "home";
}
}
你的jsp頁
<form:form modelAttribute="event"> <!--set the model attribute here -->
<form:input path="news" value="${events.get(0).news}" />
</form:form>
0
這是我的代碼,請看看和s唉我可能是做錯了, JAVA
public ModelAndView userEditProfile(@ModelAttribute("userDetails") UserFormbean registration,BindingResult result,HttpServletRequest request){
ModelAndView mav=null;
HttpSession httpSession=null;
List userProfileList=new ArrayList();
httpSession=request.getSession();
if (httpSession != null) {
UserFormbean formbean=(UserFormbean)httpSession.getAttribute("UserRegistrationFormBean");
userProfileList= userRegistrationService.getUserProfileInfo(formbean);
mav=new ModelAndView("EditProfile");
mav.addObject("userProfileInfoList", userProfileList);
}
return mav;
}
JSP::
-----
<c:if test="${not empty userProfileInfoList}">
<c:forEach var="temp" items="${userProfileInfoList}">
<div>
<form:label path="userRegistration.email"><spring:message code="label.email"/></form:label>
<form:input path ="userRegistration.email" value="${temp.get(0).UserRegistration.email}"/>
<form:errors path="userRegistration.email"/>
</div>
<div>
<form:label path="userRegistration.firstName"><spring:message code="label.firstname"/></form:label>
<form:input path ="userRegistration.firstName" value="${temp.get(0).UserRegistration.firstName}"/>
<form:errors path="userRegistration.firstName"/>
</div>
<div>
<form:label path="userRegistration.lastName"><spring:message code="label.lastname"/></form:label>
<form:input path ="userRegistration.lastName" value="${temp.get(0).UserRegistration.lastName}"/>
<form:errors path="userRegistration.lastName"/>
</div>
</c:forEach>
</c:if>
+0
我做到了這一點,它的工作。
相關問題
- 1. MVC數據庫圖像顯示彈簧
- 2. 如何從數據庫中獲取值phpmyadmin並顯示
- 3. 彈簧數據JPA獲取
- 4. 顯示在Html.Actionlink()中從數據庫中獲取的值mvc3
- 5. 如何在gridview中顯示數據庫獲取的數據?
- 6. 如何從數據庫中獲取值
- 7. 從MySQL數據庫獲取值以顯示在JSP中(JAVA)
- 8. Codeigniter從mysql數據庫獲取值並在html表中顯示
- 9. 如何獲取並顯示數據庫中最大的值?
- 10. PHP - 從數據庫中獲取值並顯示已知值
- 11. 如何從數據庫中獲取值以顯示在下拉列表中?
- 12. 如何從數據庫中獲取值並在android應用程序中顯示
- 13. 如何從數據庫中獲取值並在下拉列表中顯示
- 14. 如何在彈簧中使用投影獲取數據
- 15. 從數據庫中獲取的值未顯示
- 16. 如何從數據庫中獲取數據並將其顯示在PHP中?
- 17. 如何從數據庫中獲取數據並在視圖中顯示
- 18. 彈簧數據JPA - 獲取列中的所有唯一值
- 19. 從數據庫中獲取後JSON對象不顯示值
- 20. 如何從背景中獲取數據在彈出頁面中顯示
- 21. 如何顯示數據從數據庫中獲取表視圖在iphone
- 22. 使用彈簧MVC顯示來自數據庫的圖像MVC
- 23. 如何以彈簧形式顯示值:從arrayList輸入?
- 24. 如何從表中獲取顯示值?
- 25. 從數據庫中獲取數據並在laravel中顯示數據庫中的值
- 26. 彈簧數據庫重用
- 27. 如何從SQLite數據庫獲取特定數據和在TextView的顯示它
- 28. 從數據庫中獲取值並在android的TextView中顯示它
- 29. 彈簧數據庫中的JPA繼承
- 30. 從數據庫中獲取xml數據,然後顯示它
是的ModelAttribute相同命令名? –
是啊沒有區別 –
我嘗試訪問使用上述技術的元素,但我面臨一個問題,諸如名稱,電子郵件等字段被包裝在父bean中。在這種情況下,訪問這些元素的語法應該是什麼?我得到這個異常「org.apache.jasper.JasperException:/WEB-INF/views/EditProfile.jsp(31,3)當沒有指定默認命名空間時,函數get必須與前綴一起使用」 –