构建之法--探索篇(二)
这几天没有特别难过的bug,所以来说一下我最近做的按条件查找吧!
首先在当初既定的custDao、CustDaoImpl、custService、custServiceImpl中添加上public List<Cust> findCustByCondition(Cust cust);
然后再action包下面建立新的class:FindCustAction.java内容如下:
package com.crm.action;
import java.util.Map;
import com.crm.bean.Cust;
import com.crm.service.CustService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class FindCustAction extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
private CustService custService;
Cust cust;
public CustService getCustService() {
return custService;
}
public void setCustService(CustService custService) {
this.custService = custService;
}
public Cust getCust() {
return cust;
}
public void setCust(Cust cust) {
this.cust = cust;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
Map map = (Map)ActionContext.getContext().get("request");
map.put("list", this.custService.findCustByCondition(cust));
return SUCCESS;
}
}
做完以后需要进行两大配置:
applicationContext.xml
这里我们的类就起了一个别名,在以后的配置中要用前面的id名称;(下面的name中的名字一定要和新定义的类FindCustAction中的custService的对象一致。
其次:配置Struts.xml
依旧是两个一致就好了。当查询结果成功以后就会跳转到custInfo.jsp 界面
完成。
)