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运行正常 恭喜成功了

你可能感兴趣的:(html,tomcat,Web,框架,mvc)