我在获取下拉列表的值时遇到了麻烦,我有学生实体和部分实体,它们之间有一个关系船,在jsp中它就像com.chan.Eschool.student.model.Section@26552d
而不是这个在jsp中,我需要获得特定的bean属性名称,如部分名称
@Entity
@Table(name="section")
public class Section implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private String sectionName;
private School school;
private List<Student> studentList;
public static long getSerialversionuid() {
return serialVersionUID;
}
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getSectionName() {
return sectionName;
}
public void setSectionName(String sectionName) {
this.sectionName = sectionName;
}
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="school_id")
public School getSchool() {
return school;
}
public void setSchool(School school) {
this.school = school;
}
@OneToMany( mappedBy = "section" )
public List<Student> getStudentList() {
return studentList;
}
public void setStudentList(List<Student> studentList) {
this.studentList = studentList;
}
}
学生示范班
@Entity
@Table(name="student")
public class Student {
private long id;
private String student_name;
private String roll_no;
private String standard;
private School school;
private Address address;
private StudentPhysicalInfo physicalInfo;
private Section section;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getStudent_name() {
return student_name;
}
public void setStudent_name(String student_name) {
this.student_name = student_name;
}
public String getRoll_no() {
return roll_no;
}
public void setRoll_no(String roll_no) {
this.roll_no = roll_no;
}
public String getStandard() {
return standard;
}
public void setStandard(String standard) {
this.standard = standard;
}
@ManyToOne
@JoinColumn(name="school_id")
public School getSchool() {
return school;
}
public void setSchool(School school) {
this.school = school;
}
@Embedded
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
@OneToOne(mappedBy="student",cascade=CascadeType.ALL)
public StudentPhysicalInfo getPhysicalInfo() {
return physicalInfo;
}
public void setPhysicalInfo(StudentPhysicalInfo physicalInfo) {
this.physicalInfo = physicalInfo;
}
@ManyToOne
@JoinColumn(name =" section_Id")
public Section getSection() {
return section;
}
public void setSection(Section section) {
this.section = section;
}
}
我的道实现是这样的
@Override
public List<Section> getSections() {
Session session = this.sessionFactory.getCurrentSession();
Query query = session.createQuery( "from Section s" );
List<Section> sectionList = query.list();
return sectionList;
}
像金丝马龙一样。
<div class="panel-body">
<c:url value="/student/register" var="register" />
<form:form cssClass="form-horizontal" role="form" action="${register}" method="post" modelAttribute="student">
<div class="form-group">
<div class="col-sm-8 col-sm-offset-2">
<form:input path="student_name" class="form-control" id="inputEmail3"
placeholder="student_name" />
</div>
<div class="col-sm-8 col-sm-offset-2">
<form:errors path="student_name" />
</div>
</div>
<div class="form-group">
<div class="col-sm-8 col-sm-offset-2">
<form:input path="roll_no" class="form-control" id="inputEmail3"
placeholder="roll_no" />
</div>
<div class="col-sm-8 col-sm-offset-2">
<form:errors path="roll_no" />
</div>
</div>
<div class="form-group">
<div class="col-sm-8 col-sm-offset-2">
<form:input path="standard" class="form-control" id="inputEmail3"
placeholder="Standard" />
</div>
<div class="col-sm-8 col-sm-offset-2">
<form:errors path="standard" />
</div>
</div>
<h4 class="text-center">Address Details</h4>
<div class="form-group">
<div class="col-sm-8 col-sm-offset-2">
<form:input path="address.area" class="form-control" id="inputEmail3"
placeholder="Area" />
</div>
<div class="col-sm-8 col-sm-offset-2">
<form:errors path="section" />
</div>
</div>
<div class="form-group">
<div class="col-sm-8 col-sm-offset-2">
<form:input path="address.city" class="form-control" id="inputEmail3"
placeholder="City" />
</div>
<div class="col-sm-8 col-sm-offset-2">
<form:errors path="address.city" />
</div>
</div>
<div class="form-group">
<div class="col-sm-8 col-sm-offset-2">
<form:input path="address.country" class="form-control" id="inputEmail3"
placeholder="Country" />
</div>
<div class="col-sm-8 col-sm-offset-2">
<form:errors path="address.country" />
</div>
</div>
<div class="form-group">
<div class="col-sm-8 col-sm-offset-2">
<form:input path="address.pin" class="form-control" id="inputEmail3"
placeholder="pin" />
</div>
<div class="col-sm-8 col-sm-offset-2">
<form:errors path="address.pin" />
</div>
</div>
<div class="form-group">
<div class="col-sm-8 col-sm-offset-2">
<form:input path="address.state" class="form-control" id="inputEmail3"
placeholder="State" />
</div>
<div class="col-sm-8 col-sm-offset-2">
<form:errors path="address.state" />
</div>
</div>
<div class="form-group">
<div class="col-sm-8 col-sm-offset-2">
<form:input path="address.street" class="form-control" id="inputEmail3"
placeholder="Street" />
</div>
<div class="col-sm-8 col-sm-offset-2">
<form:errors path="address.street" />
</div>
</div>
<form:select path="section">
<form:options items="${sectionsList}"/>
</form:select>
<div class="form-group last">
<div class="col-sm-offset-3 col-sm-9">
<button type="submit" class="btn btn-success">Sign Up</button>
<button type="reset" class="btn btn-default">Reset</button>
</div>
</div>
</form:form>
</div>
</div>
</div>
</div>
</div>
</section>
控制器就像
@RequestMapping(value="/student/register",method=RequestMethod.GET)
public String registerStudent(Model model,@ModelAttribute Student student) {
List<Section> sectionsList = (List<Section>) sectionService.getSections();
for(Section section : sectionsList) {
System.out.println("Sections are "+ " "+section.getSectionName());
}
model.addAttribute("sectionsList",sectionsList);
return "student/registration";
}
我对这个问题的最后润色是如何获得指定bean属性名的下拉值(这里我想获得bean属性名称,如sectionName
)com.chan.Eschool.student.model.Section@26552d
请引导我哪里错了
创建地图
@RequestMapping(value="/student/register",method=RequestMethod.GET)
public String registerStudent(Model model,@ModelAttribute Student student) {
List<Section> sectionsList = (List<Section>) sectionService.getSections();
Map<Integer, String> sections = new LinkedHashMap<Integer, String>();
for(Section section : sectionsList) {
sections.put(section.getId(), section.getSectionName());
}
model.addAttribute("sectionsList",sectionsList);
model.addAttribute("sections",sections);
return "student/registration";
}
并通过调用< code >将其绑定到jsp
这是我第一次体验提升::property_tree我找不到一种方法来重现从留档(如何访问属性树中的数据)之后的树中获取值的方法。这是我为尝试属性树而编写的简单代码: 这是输出: 如<code>树所示。get_value(“whather”)在树中不返回值。get_value(“null”)不引发异常,并且<code>get_optional 我的环境是:
我对这段代码有一个问题: 当我保存它时,我会得到以下错误代码: 未捕获的ReferenceError:未定义birthDate 因此,基本上我正在训练获取值“05June 2001”,以便将其作为参数传递给Date函数,但我不能这样做,不过我可以从浏览器控制台访问该值,在那里我确实犯了错误,并提前表示感谢。
问题内容: 我有这样的下拉菜单。我想要的是,我想使用 PHP 在按钮提交中获得选定的值和文本。我的意思是如果它被选为第一。我想同时获得 1 和 Cat 请帮忙。谢谢。 问题答案: 使用您的$ animals列表生成下拉列表;您现在可以获得密钥和该密钥的值。
这是react项目中的bootcamp.js文件 console.log(训练营)显示未定义。Plzz帮助
我有一个下拉列表,客户端必须选择一个值,然后它将在mysql db中持久化好的,我这样做了,但我希望当客户端选择一个值时,我得到该值,然后我执行if语句示例: 如果选择的值为:CIN,则为compte。setcomptenumber(25364138);就像那样 这是我的控制器: 我的html:
问题内容: 如何使用JavaScript从下拉列表中获取选定的值? 我尝试了下面的方法,但是它们都返回选择的索引而不是值: 问题答案: 如果您有一个如下所示的select元素: 运行此代码: 将成为。如果您真正想要的是,请执行以下操作: 这将成为