s:select list="#request.test" 显示对象的内存地址值,不能显示属性值?
被这个问题搞死了
在idea中编辑的.......
现在显示效果如下:显示不到文字的,显示一个object的内存地址,但是在下面的table就能显示出来....
我的代码:
Test.java
package com.entities;
public class Test {
private int id;
private String departmentName;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
}
DepartmentDao.java
package com.service;
import com.entities.Test;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import java.util.List;
public class DepartmentDao {
private SessionFactory factory;
public void setFactory(SessionFactory factory) {
this.factory = factory;
}
public Session getSeesion() {
return factory.getCurrentSession();
}
public List<Test> getAll() {
String hql = "from Test";
return getSeesion().createQuery(hql).list();
}
}
DepartmentService.java
package com.service;
import com.entities.Test;
import java.util.List;
public class DepartmentService {
private DepartmentDao departmentDao;
public void setDepartmentDao(DepartmentDao departmentDao) {
this.departmentDao = departmentDao;
}
public List<Test> getAll() {
return departmentDao.getAll();
}
}
DepartmentAction.java
package com.actions;
import com.service.DepartmentService;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.interceptor.RequestAware;
import java.util.Map;
public class DepartmentAction extends ActionSupport implements RequestAware {
private Map<String, Object> request;
private DepartmentService departmentService;
public void setDepartmentService(DepartmentService departmentService) {
this.departmentService = departmentService;
}
@Override
public void setRequest(Map<String, Object> map) {
this.request = map;
}
public String list() {
request.put("test", departmentService.getAll());
return "list";
}
}
jsp:
这样写也一样:
<s:select list="#request.test" listkey="id" listvalue="departmentName" headerValue="输入部门">
</s:select>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>show result</title>
</head>
<body>
<h4>show department info</h4>
<s:debug></s:debug>
<s:form action="/" method="post" namespace="/">
<s:select list="#request.test" listkey="#request.test.id" listvalue="#request.test.departmentName" headerValue="输入部门">
</s:select>
<s:submit></s:submit>
</s:form>
<h4>对比,检测request是否有值</h4>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td>ID</td>
<td>DEPARTMENT</td>
<td>DEPARTMENT-Object</td>
</tr>
<s:iterator value="#request.test">
<tr>
<td>${id}</td>
<td>${departmentName}</td>
<td>${test}</td>
</tr>
</s:iterator>
</table>
</body>
</html>
使用的是spring4,hibernate5,struts2...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论