使用hibernate时,数据不会显示在struts2 jquery网格中
我是struts2 jquery网格的初学者。网格显示在浏览器上,但没有填充网格。主要问题是MyActionTable.java中没有its。请帮帮我 Customer.java使用hibernate时,数据不会显示在struts2 jquery网格中,jquery,hibernate,struts2,grid,Jquery,Hibernate,Struts2,Grid,我是struts2 jquery网格的初学者。网格显示在浏览器上,但没有填充网格。主要问题是MyActionTable.java中没有its。请帮帮我 Customer.java package example; public class Customer implements java.io.Serializable { private Integer id; private String name; public Customer() { } public Customer
package example;
public class Customer implements java.io.Serializable {
private Integer id;
private String name;
public Customer() {
}
public Customer(String name) {
this.name = name;
}
public Customer(Integer id, String name) {
this.id = id;
this.name = name;
}
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}}
package example;
import com.opensymphony.xwork2.ActionSupport;
import database_util.MyFilterHib;
import java.util.*;
import org.hibernate.*;
import org.hibernate.cfg.Configuration;
public class MyActionTable extends ActionSupport{
public MyActionTable() {
System.out.println("ActionTable********************");
}
private List<Customer> gridModel;
private List<Customer> myCustomers;
private Integer rows = 0;
private Integer page = 0;
private Integer total = 0;
private Integer record = 0;
private String sord;
private String sidx;
private String searchField;
private String searchString;
private String searchOper;
private boolean loadonce = false;
public List<Customer> getGridModel() {
System.out.println("31****************");
return gridModel;
}
public void setGridModel(List<Customer> gridModel) {
this.gridModel = gridModel;
}
public List<Customer> getMyCustomers() {
return myCustomers;
}
public void setMyCustomers(List<Customer> myCustomers) {
this.myCustomers = myCustomers;
}
public Integer getRows() {
return rows;
}
public void setRows(Integer rows) {
this.rows = rows;
}
public Integer getPage() {
return page;
}
public void setPage(Integer page) {
this.page = page;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public Integer getRecord() {
return record;
}
public void setRecord(Integer record) {
this.record = record;
}
public String getSord() {
return sord;
}
public void setSord(String sord) {
this.sord = sord;
}
public String getSidx() {
return sidx;
}
public void setSidx(String sidx) {
this.sidx = sidx;
}
public String getSearchField() {
return searchField;
}
public void setSearchField(String searchField) {
this.searchField = searchField;
}
public String getSearchString() {
return searchString;
}
public void setSearchString(String searchString) {
this.searchString = searchString;
}
public String getSearchOper() {
return searchOper;
}
public void setSearchOper(String searchOper) {
this.searchOper = searchOper;
}
public boolean isLoadonce() {
return loadonce;
}
public void setLoadonce(boolean loadonce) {
this.loadonce = loadonce;
}
public String getJSON()
{
return getAllApplicationData();
}
public String getAllApplicationData(){
String result = SUCCESS;
Query q = null;
try{
SessionFactory sessionfactory=new Configuration().configure().buildSessionFactory();
SessionFactory sf=MyFilterHib.getSessionFactory();
Session session;
session = sessionfactory.getCurrentSession();
session.beginTransaction();
q = session.createQuery("from Customer");
this.setGridModel(q.list());
if(this.getGridModel()!=null)
System.out.println("gridModel.Size() : "+this.getGridModel().size());
else
System.out.println("gridModel null");
int to = (rows * page);
int from = to - rows;
//Count Rows (select count(*) from custumer)
record = gridModel.size();
System.out.println("record : "+record);
//Your logic to search and select the required data.
//gridModel = CustumerDAO.find(from, to);
//calculate the total pages for the query
total =(int) Math.ceil((double)record / (double)rows);
System.out.println("total : "+total);
}catch(Exception e){
e.printStackTrace();
}
return result;
}}
MyActionTable.java
package example;
public class Customer implements java.io.Serializable {
private Integer id;
private String name;
public Customer() {
}
public Customer(String name) {
this.name = name;
}
public Customer(Integer id, String name) {
this.id = id;
this.name = name;
}
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}}
package example;
import com.opensymphony.xwork2.ActionSupport;
import database_util.MyFilterHib;
import java.util.*;
import org.hibernate.*;
import org.hibernate.cfg.Configuration;
public class MyActionTable extends ActionSupport{
public MyActionTable() {
System.out.println("ActionTable********************");
}
private List<Customer> gridModel;
private List<Customer> myCustomers;
private Integer rows = 0;
private Integer page = 0;
private Integer total = 0;
private Integer record = 0;
private String sord;
private String sidx;
private String searchField;
private String searchString;
private String searchOper;
private boolean loadonce = false;
public List<Customer> getGridModel() {
System.out.println("31****************");
return gridModel;
}
public void setGridModel(List<Customer> gridModel) {
this.gridModel = gridModel;
}
public List<Customer> getMyCustomers() {
return myCustomers;
}
public void setMyCustomers(List<Customer> myCustomers) {
this.myCustomers = myCustomers;
}
public Integer getRows() {
return rows;
}
public void setRows(Integer rows) {
this.rows = rows;
}
public Integer getPage() {
return page;
}
public void setPage(Integer page) {
this.page = page;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public Integer getRecord() {
return record;
}
public void setRecord(Integer record) {
this.record = record;
}
public String getSord() {
return sord;
}
public void setSord(String sord) {
this.sord = sord;
}
public String getSidx() {
return sidx;
}
public void setSidx(String sidx) {
this.sidx = sidx;
}
public String getSearchField() {
return searchField;
}
public void setSearchField(String searchField) {
this.searchField = searchField;
}
public String getSearchString() {
return searchString;
}
public void setSearchString(String searchString) {
this.searchString = searchString;
}
public String getSearchOper() {
return searchOper;
}
public void setSearchOper(String searchOper) {
this.searchOper = searchOper;
}
public boolean isLoadonce() {
return loadonce;
}
public void setLoadonce(boolean loadonce) {
this.loadonce = loadonce;
}
public String getJSON()
{
return getAllApplicationData();
}
public String getAllApplicationData(){
String result = SUCCESS;
Query q = null;
try{
SessionFactory sessionfactory=new Configuration().configure().buildSessionFactory();
SessionFactory sf=MyFilterHib.getSessionFactory();
Session session;
session = sessionfactory.getCurrentSession();
session.beginTransaction();
q = session.createQuery("from Customer");
this.setGridModel(q.list());
if(this.getGridModel()!=null)
System.out.println("gridModel.Size() : "+this.getGridModel().size());
else
System.out.println("gridModel null");
int to = (rows * page);
int from = to - rows;
//Count Rows (select count(*) from custumer)
record = gridModel.size();
System.out.println("record : "+record);
//Your logic to search and select the required data.
//gridModel = CustumerDAO.find(from, to);
//calculate the total pages for the query
total =(int) Math.ceil((double)record / (double)rows);
System.out.println("total : "+total);
}catch(Exception e){
e.printStackTrace();
}
return result;
}}
包示例;
导入com.opensymphony.xwork2.ActionSupport;
导入数据库_util.MyFilterHib;
导入java.util.*;
导入org.hibernate.*;
导入org.hibernate.cfg.Configuration;
公共类MyActionTable扩展了ActionSupport{
公共MyActionTable(){
System.out.println(“ActionTable**********************”;
}
私有列表模型;
私人客户名单;
私有整数行=0;
私有整数页=0;
私有整数合计=0;
私有整数记录=0;
私有字符串排序;
私有字符串sidx;
私有字符串搜索字段;
私有字符串搜索字符串;
私有字符串搜索器;
私有布尔loadonce=false;
公共列表getGridModel(){
System.out.println(“31****************”);
返回网格模型;
}
公共void setGridModel(列表gridModel){
this.gridModel=gridModel;
}
公共列表getMyCustomers(){
归还我的客户;
}
公共作废setMyCustomers(列出myCustomers){
this.myCustomers=myCustomers;
}
公共整数getRows(){
返回行;
}
公共void集合行(整数行){
this.rows=行;
}
公共整数getPage(){
返回页面;
}
公共无效设置页(整数页){
this.page=page;
}
公共整数getTotal(){
返回总数;
}
公共void集合总计(整数总计){
这个.总计=总计;
}
公共整数getRecord(){
返回记录;
}
公共void setRecord(整数记录){
this.record=记录;
}
公共字符串getSord(){
返回sord;
}
公共无效设置命令(字符串排序){
this.sord=sord;
}
公共字符串getSidx(){
返回sidx;
}
公共void setSidx(字符串sidx){
this.sidx=sidx;
}
公共字符串getSearchField(){
返回搜索字段;
}
公共无效设置搜索字段(字符串搜索字段){
this.searchField=searchField;
}
公共字符串getSearchString(){
返回搜索字符串;
}
public void setSearchString(字符串搜索字符串){
this.searchString=searchString;
}
公共字符串getSearchOper(){
返回搜索操作器;
}
公共无效设置搜索器(字符串搜索器){
this.searchOper=searchOper;
}
公共布尔值isLoadonce(){
返回装载一次;
}
公共void setLoadonce(布尔loadonce){
this.loadonce=loadonce;
}
公共字符串getJSON()
{
返回getAllApplicationData();
}
公共字符串getAllApplicationData(){
字符串结果=成功;
查询q=null;
试一试{
SessionFactory SessionFactory=新配置().configure().buildSessionFactory();
SessionFactory sf=MyFilterHib.getSessionFactory();
会议;
session=sessionfactory.getCurrentSession();
session.beginTransaction();
q=session.createQuery(“来自客户”);
这个.setGridModel(q.list());
if(this.getGridModel()!=null)
System.out.println(“gridModel.Size():”+this.getGridModel().Size());
其他的
System.out.println(“gridModel null”);
int to=(行*页);
int from=to-行;
//计算行数(从custumer中选择Count(*)
record=gridModel.size();
System.out.println(“记录:+record”);
//搜索和选择所需数据的逻辑。
//gridModel=CustumerDAO.find(从,到);
//计算查询的总页数
总计=(int)Math.ceil((双)记录/(双)行);
系统输出打印项次(“总计:+总计);
}捕获(例外e){
e、 printStackTrace();
}
返回结果;
}}
HelloWorld.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@taglib prefix="sj" uri="/struts-jquery-tags" %>
<%@taglib prefix="sjg" uri="/struts-jquery-grid-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<sj:head jqueryui="true" jquerytheme="redmond"></sj:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Grid Demo</title>
</head>
<body>
<s:url id="remoteurl" action="ntable"/>
<sjg:grid
id="gridtable"
caption="Customer Examples"
dataType="json"
href="%{remoteurl}"
pager="true"
gridModel="gridModel"
rowList="10,15,20"
rowNum="15"
rownumbers="true"
>
<sjg:gridColumn name="id" index="id" title="ID" formatter="integer" sortable="false" key="true"/>
<sjg:gridColumn name="name" index="name" title="Name" editable="true"/>
</sjg:grid>
</body>
</html>
网格演示
struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="example.xml"/>
<!-- Configuration for the default package. -->
<package name="example" extends="struts-default,json-default" namespace="/">
<action name="ntable" class="example.MyActionTable" method="getJSON">
<result name="success" type="json"/>
</action>
</package>
</struts>
您的JSON请求是否成功?请检查您的JavaScript控制台和JSON操作。它不会进入任何操作。我检查了所有内容,但找不到错误