Java 用Struts 2中的数据库值填充Dropdownlist,Hibernate
我试图用表中的值填充下拉列表。该页面使用strust2和hibernate访问数据库 我可以查看注册页面(其中包含必须填充数据库值的下拉列表) 但下拉列表中不显示任何值 index.jspJava 用Struts 2中的数据库值填充Dropdownlist,Hibernate,java,hibernate,jsp,orm,struts2,Java,Hibernate,Jsp,Orm,Struts2,我试图用表中的值填充下拉列表。该页面使用strust2和hibernate访问数据库 我可以查看注册页面(其中包含必须填充数据库值的下拉列表) 但下拉列表中不显示任何值 index.jsp <s:url id="url" action="registerAction"> </s:url> <s:a href="%{url}">Register</s:a> DAO public class UserDao { List<Mo
<s:url id="url" action="registerAction">
</s:url>
<s:a href="%{url}">Register</s:a>
DAO
public class UserDao {
List<Month> allMonths = new ArrayList<Month>();
public List<Month> getAllMonths() {
return allMonths;
}
public void setAllMonths(List<Month> allMonths) {
this.allMonths = allMonths;
}
public Session getSession() {
return HibernateUtil.getSession();
}
public void closeSession() {
HibernateUtil.closeSession();
}
public UserDao() {
}
public List<Month> getMonths() {
Session session = getSession();
Transaction t = session.beginTransaction();
allMonths = (List<Month>) session.createQuery("FROM Month").list();
System.out.println("In constructor " + allMonths);
t.commit();
closeSession();
return allMonths;
}
}
试着用你的刀做这个
public List<Month> getMonths() {
Session session = getSession();
Transaction t = session.beginTransaction();
allMonths = (List<Month>) session.createCriteria(Month.class).list();
System.out.println("In constructor " + allMonths);
t.commit();
closeSession();
return allMonths;
}
public List getMonths(){
Session=getSession();
事务t=session.beginTransaction();
allMonths=(List)session.createCriteria(Month.class.List();
System.out.println(“建造商内”+所有月份);
t、 提交();
closeSession();
返回所有月份;
}
顺便说一下,这里的异常与action类无关,因为该异常显然是hibernate异常。尝试在action类中放置断点(如果您使用的是IDE),或者放置System.out.println语句以查看代码是否正在进入action类。尝试在DAO中执行此操作
public List<Month> getMonths() {
Session session = getSession();
Transaction t = session.beginTransaction();
allMonths = (List<Month>) session.createCriteria(Month.class).list();
System.out.println("In constructor " + allMonths);
t.commit();
closeSession();
return allMonths;
}
public List getMonths(){
Session=getSession();
事务t=session.beginTransaction();
allMonths=(List)session.createCriteria(Month.class.List();
System.out.println(“建造商内”+所有月份);
t、 提交();
closeSession();
返回所有月份;
}
顺便说一下,这里的异常与action类无关,因为该异常显然是hibernate异常。尝试在action类中放置断点(如果您使用的是IDE),否则请放置System.out.println语句以查看代码是否正在进入action类。Hibernate是一个ORM(对象关系映射)框架,用于将POJO映射到数据库架构。就你而言,现在是月
。因为您使用注释将对象映射到表,所以应该在hibernate.cfg.xml
<mapping class="package.to.persistence.Month" />
如果不映射类,Hibernate无法在对象中找到注释。Hibernate是一个ORM(对象关系映射)框架,用于将POJO映射到数据库架构。就你而言,现在是月
。因为您使用注释将对象映射到表,所以应该在hibernate.cfg.xml
<mapping class="package.to.persistence.Month" />
如果不映射类,Hibernate将无法在对象中找到批注。它可以工作..谢谢..我的错误..至少花2周时间在internet上搜索此问题..它可以工作..谢谢..我的错误..至少花2周时间在internet上搜索此问题..错误是由于没有在Hibernate配置文件中添加映射..指出罗马C。。也感谢您伸出援手..错误是由于没有在hibernate配置文件中添加映射..Roman C.指出。。也谢谢你伸出援手。。
org.hibernate.hql.ast.QuerySyntaxException: Month is not mapped [from Month]
public List<Month> getMonths() {
Session session = getSession();
Transaction t = session.beginTransaction();
allMonths = (List<Month>) session.createCriteria(Month.class).list();
System.out.println("In constructor " + allMonths);
t.commit();
closeSession();
return allMonths;
}
<mapping class="package.to.persistence.Month" />