spring注入问题
我写了个分页的pageAction.所有要分页的action都继承pageAction
pageActoin中的pageModel(分页组件),pageTemplate(分页的查询方法)是spring注入的.
pageModel中的pageNo设置了默认值为1,pageSize默认值为2
但在pageAction中取值都是空
xml
<bean name="/pageAction" class="com.syaccp.salary.common.page.pageAcition.PageAction">
<property name="pageTemplate" ref="pageTemplate"/>
<property name="pageModel" ref="pageModel"/>
</bean>
pageAction代码:
public class PageAction extends DispatchAction {
private PageTemplate pageTemplate;
private PageModel pageModel;
public void setPageModel(PageModel pageModel) {
this.pageModel = pageModel;
}
public void setPageTemplate(PageTemplate pageTemplate) {
this.pageTemplate = pageTemplate;
}
public ActionForward queryPage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse reponse,String modelName,String conditionfinal) throws Exception {
Pageform pageform = (Pageform)form;
if(pageform==null || pageform.getPageNo()==0) {
int pageNo = pageModel.getPageNo(); 这里值为空
int pageSize = pageModel.getPageSize(); 这里值为空
pageModel = pageTemplate.query(modelName, null, null,pageNo,pageSize);
}else {
BeanUtils.copyProperties(pageModel, pageform);
pageModel = pageTemplate.query(modelName, null, pageModel.getOrderName(), pageModel.getPageNo(), pageModel.getPageSize());
}
request.setAttribute("pageModel", pageModel);
return mapping.findForward("sessuce");
}
}
pageModel代码:
/**分页组件
* @author Administrator
*
*/
public class PageModel {
//总页数
private int totalPage;
//结果集
private List resultList;
//当前页码
private int pageNo=1;
//记录条数
private int pageSize=2;
//第一页
private int topPage;
//上一页
private int upPage;
//下一页
private int nextPage;
//最后一页
private int lastPage;
//排序名称
private String orderName;
//最后一页
public int getLastPage() {
return this.totalPage;
}
public void setLastPage(int lastPage) {
this.lastPage = this.totalPage;
}
//下一页
public int getNextPage() {
return nextPage;
}
public void setNextPage(int pageNo) {
if(this.pageNo >= this.totalPage) {
this.nextPage = this.totalPage;
}else {
this.nextPage = this.pageNo+1;
}
}
//当前页码
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}
// 显示记录
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
//第一页
public int getTopPage() {
return 1;
}
public void setTopPage(int topPage) {
this.topPage = 1;
}
//总页面数
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
//上一页
public int getUpPage() {
return upPage;
}
public void setUpPage(int pageNo) {
if(this.pageNo <= 1) {
this.upPage = 1;
}else {
this.upPage = this.pageNo - 1;
}
}
public List getResultList() {
return resultList;
}
public void setResultList(List resultList) {
this.resultList = resultList;
}
public String getOrderName() {
return orderName;
}
public void setOrderName(String orderName) {
this.orderName = orderName;
}
}
pageTemplate代码:
public class PageTemplate extends HibernateDaoSupport {