玩玩Spring之hibernate+ webwork+ spring添删改查示例

主演:webwork
   配角:struts、jsp、hibernate、spring等
  
  借着吹spring的风,今天笔者给大家介绍一种很多人都非常欣赏的轻量极、高雅的J2EE组合,那就是hibernate+ webwork+ spring。说介绍不准确,应该还只是一个简单的演示,毕竟webwork的赞歌已经有很多人唱过了,这里就不重复(主要还是因为唱不出来,惭愧!)。我只希望能通过简单的代码,让大家去体会webwork的高雅、过人之处。
 
  同样是上一篇中有关一个用户表“添删改查”的例子,这里只是把Web层改成使用webwork实现,下面我们直接介绍Web开发部分,其它部分的开发请照搬前面一篇的例子,新人可以结合上个例子中的Struts部分进行看。

1、写Action

  webwork跟Struts乃至其它的MVC框架一样,都有一个处理Web请求的Action,我们来看看本例子中这个Action的内容。下面是UserManageAction.java的全部代码:
 

package com.easyjf.webwork.action;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import com.easyjf.example.business.IUser;
import com.easyjf.example.business.IUserService;
import com.easyjf.util.CommUtil;
import com.easyjf.web.tools.IPageList;
import com.easyjf.web.tools.ListQuery;
import com.easyjf.web.tools.PageList;
import com.opensymphony.webwork.interceptor.ParameterAware;
import com.opensymphony.xwork.ActionSupport;
import com.opensymphony.xwork.Preparable;
public class UserManageAction extends ActionSupport implements ParameterAware,Preparable {
private List allUser;
private IUserService userService; 
private IUser user;
private Map parameters;
//用户查询
public String query() throws Exception { 
 String[] temp=(String[])parameters.get("page");
 int currentPage=CommUtil.null2Int(temp!=null?temp[0]:"0");
 temp=(String[])parameters.get("pageSize");
 int pageSize=CommUtil.null2Int(temp!=null?temp[0]:"0");
 if(currentPage<1)currentPage=1;
 if(pageSize<1)pageSize=10;
 String scope="1=1";
 Collection paras=new ArrayList();
 temp=(String[])parameters.get("orderType");
 String orderType=CommUtil.null2String(temp!=null?temp[0]:""); 
 temp=(String[])parameters.get("orderField");
 String orderField=CommUtil.null2String(temp!=null?temp[0]:"");
 temp=(String[])parameters.get("queryUserName");
 String userName=CommUtil.null2String(temp!=null?temp[0]:"");
 temp=(String[])parameters.get("queryTel");
 String tel=CommUtil.null2String(temp!=null?temp[0]:"");    
 if(!userName.equals(""))
 {
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值