2008-01-25
easyjweb框架的查询
我把成功的代码贴出来 避免后人也遇到此问题
在crud的基础上加查询只需要在 qurey包加一个类继承com.easyjf.core.support.query.QueryObject覆盖其customizeQuery方法
com.test.query.UserQuery代码
package com.test.query;
import java.util.List;
import com.easyjf.core.support.query.QueryObject;
public class UserQuery extends QueryObject {
private String userName = "";
private String userPwd = "";
public String getUserPwd() {
return userPwd;
}
public void setUserPwd(String userPwd) {
this.userPwd = userPwd;
}
@Override
public void customizeQuery() {
if (!"".equals(userName)) {
addQuery("obj.userName", "%" + userName + "%", "like");
}
if (!"".equals(userPwd)) {
addQuery("obj.userPwd", "%" + userPwd + "%", "like");
}
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
注意把
private String userName = "";
private String userPwd = "";
不然初始页面会执行查询
然后就是修改action
com.test.mvc.userAction
package com.test.mvc;
import java.io.Serializable;
import java.util.List;
import com.easyjf.container.annonation.Action;
import com.easyjf.container.annonation.Inject;
import com.easyjf.core.support.query.IQueryObject;
import com.easyjf.web.tools.AbstractCrudAction;
import com.easyjf.web.tools.IPageList;
import com.test.domain.user;
import com.test.service.IuserService;
/**
* userAction
*
* @author EasyJWeb 1.0-m2 $Id: userAction.java,v 0.0.1 2008-1-24 9:55:22
* EasyJWeb 1.0-m2 Exp $
*/
@Action
public class userAction extends AbstractCrudAction {
@Inject
private IuserService service;
/*
* set the current service return service
*/
public void setService(IuserService service) {
this.service = service;
}
/*
* to get the entity class
*/
@SuppressWarnings("unchecked")
protected Class entityClass() {
return user.class;
}
/*
* to find the entity object
*/
protected Object findEntityObject(Serializable id) {
return service.getuser((Long) id);
}
/*
* to get the entity query param queryObject return IPageList
*/
protected IPageList queryEntity(IQueryObject queryObject) {
return service.getuserBy(queryObject);
}
/*
* to remove an entity param id
*/
protected void removeEntity(Serializable id) {
service.deluser((Long) id);
}
/*
* to batch remove the entities param ids
*/
protected void batchRemoveEntity(List<Serializable> ids) {
service.batchDelusers(ids);
}
/*
* save object to entity
*/
protected void saveEntity(Object object) {
service.adduser((user) object);
}
/*
* update an entited object
*/
protected void updateEntity(Object object) {
service.updateuser(((user) object).getId(), (user) object);
}
@Override
protected Class getQueryClass() {
return com.test.query.UserQuery.class;
}
}
然后在view层list.html的查询修改为
<tr class="caption"> <td colspan="5"> <span> 查询<b></b></span> <label for="searchbyname">项目:</label> <input size="10" id="userName" type="text" value='$!userName' name="userName" /> <input name="提交" type="submit" class="button" value='查询'/> </td> </tr>
然后打包war 放到tomcat运行正常 恭喜成功了
发表评论
提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则
- 浏览: 25348 次
- 性别:

- 来自: 珠海

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
一个自己写的很简陋的php ...
在构想 tag的中文映射如何构建 期待能做到足够的智能化
-- by kenter1643 -
一个用js+div实现的拖拽, ...
更多基于jquery的效果demohttp://interface.eyecon ...
-- by kenter1643 -
使用 jQuery(Ajax)/PHP/My ...
php-excel是一个非常简单,用于生成excel文档的php函数库。项目站点 ...
-- by kenter1643 -
DELPHI VCL组件 TTreeList ...
没有安装成功: Compile 时报 File not find:'bmp.r ...
-- by newchina -
vsftpd的配置
useradd -d 目录 用户名 passwd 用户 chown 用户名 ...
-- by kenter1643






评论排行榜