- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图将两个对象放入 JSP View 中,但是通过 getter 获取值时工作正常,而通过对象的属性引用值时会引发错误。
JSP 代码片段是:
<div class="row">
<div class="box">
<div class="col-lg-12">
<hr><h2 class="intro-text text-center">Manage Subject</h2><hr>
</div>
<div class="col-md-12">
<c:url var="addAction" value="/data-entry/subject/add" ></c:url>
<form:form action="${addAction}" commandName="subject">
<table>
<c:if test="${!empty subject.name}">
<tr>
<td>
<form:label path="id">
<spring:message text="ID"/>
</form:label>
</td>
<td>
<form:input path="id" readonly="true" size="8" disabled="true" />
<form:hidden path="id" />
</td>
</tr>
</c:if>
<tr>
<td>
<form:label path="name">
<spring:message text="Name"/>
</form:label>
</td>
<td>
<form:input path="name" />
</td>
</tr>
<tr>
<td>
<form:label path="description">
<spring:message text="Description"/>
</form:label>
</td>
<td>
<form:input path="description" />
</td>
</tr>
<tr>
<td colspan="2">
<c:if test="${!empty subject.name}">
<input type="submit"
value="<spring:message text="Edit Subject"/>" />
</c:if>
<c:if test="${empty subject.name}">
<input type="submit"
value="<spring:message text="Add Subject"/>" />
</c:if>
</td>
</tr>
</table>
</form:form>
<br>
<h3>Subject List</h3>
<c:if test="${!empty subjectlist}">
<table class="tg">
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<c:forEach items="${subjectlist}" var="subject">
<tr>
<td>${subject.getID()}</td>
<td>${subject.getName()}</td>
<td>${subject.getDescription()}</td>
<td><a href="<c:url value='/admin/subject/edit/${subject.getID()}' />" >Edit</a></td>
<td><a href="<c:url value='/admin/subject/remove/${subject.getID()}' />" >Delete</a></td>
</tr>
</c:forEach>
</table>
</c:if>
</div>
</div>
</div>
模型类:
package com.spring.schoolmanagement.model;
public class Subject {
private int id;
private String name;
private String description;
public void setID(int id) {
this.id = id;
}
public int getID() {
return this.id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public void setDescription( String description ) {
this.description = description;
}
public String getDescription() {
return this.description;
}
@Override
public String toString(){
return "{ID=" + id + ",Name=" + name + ",Description=" + description + "}";
}
}
Controller 类:
package com.spring.schoolmangement;
import java.util.Locale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.spring.schoolmanagement.dao.SubjectDAOImpl;
import com.spring.schoolmanagement.model.Subject;
/**
* Handles requests for admin specific pages.
*/
@Controller
public class AdminController {
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
@Autowired
private SubjectDAOImpl subjectService;
/**
* Simply selects the home view to render by returning its name.
*/
@RequestMapping(value = {"/admin/", "/admin"}, method = RequestMethod.GET)
public String home(Locale locale, Model model) {
return "admin-dash-board";
}
@RequestMapping(value = "/admin/student")
public String student(Model model) {
return "admin-student";
}
@RequestMapping(value = "/admin/subject")
public String displaySubjects(Model model) {
model.addAttribute("subject", new Subject());
model.addAttribute("subjectlist", this.subjectService.getAll());
return "manage-subject";
}
@RequestMapping(value = "/admin/subject/edit/{id}")
public String course(@PathVariable("id") int id, Model model) {
model.addAttribute("subject", this.subjectService.getById(id));
model.addAttribute("subjectlist", this.subjectService.getAll());
return "manage-subject";
}
}
请指出我在哪里犯了错误。
最佳答案
更改 getter/setter 方法:
public void setID(int id) {
this.id = id;
}
public int getID() {
return this.id;
}
至
public void setId(int id) {
this.id = id;
}
public int getId() {
return this.id;
}
您的 Bean 缺少命名约定,应遵循 JavaBean (read pdf section 8.8)命名约定。
关于java - 在 com.spring.schoolmanagement.model.Subject 类型上找不到属性 'id',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28984081/
例如,我有一个父类Author: class Author { String name static hasMany = [ fiction: Book,
代码如下: dojo.query(subNav.navClass).forEach(function(node, index, arr){ if(dojo.style(node, 'd
我有一个带有 Id 和姓名的学生表和一个带有 Id 和 friend Id 的 Friends 表。我想加入这两个表并找到学生的 friend 。 例如,Ashley 的 friend 是 Saman
我通过互联网浏览,但仍未找到问题的答案。应该很容易: class Parent { String name Child child } 当我有一个 child 对象时,如何获得它的 paren
我正在尝试创建一个以 Firebase 作为我的后端的社交应用。现在我正面临如何(在哪里?)找到 friend 功能的问题。 我有每个用户的邮件地址。 我可以访问用户的电话也预订。 在传统的后端中,我
我主要想澄清以下几点: 1。有人告诉我,在 iOS 5 及以下版本中,如果您使用 Game Center 设置多人游戏,则“查找 Facebook 好友”(如与好友争夺战)的功能不是内置的,因此您需要
关于redis docker镜像ENTRYPOINT脚本 docker-entrypoint.sh : #!/bin/sh set -e # first arg is `-f` or `--some-
我是一名优秀的程序员,十分优秀!