`
side91
  • 浏览: 13363 次
  • 性别: Icon_minigender_1
  • 来自: 厦门
最近访客 更多访客>>
社区版块
存档分类
最新评论

Hibernate Example.setPropertySelector

阅读更多
MyPropertySelector

package util;

import org.hibernate.criterion.Example.PropertySelector;
import org.hibernate.type.Type;

@SuppressWarnings("serial")
public class MyPropertySelector {
	private static PropertySelector NOT_NULL_BLANK_ZEROS = null;
	
	private MyPropertySelector(){
	}

	public static PropertySelector getNotNullBlankZeros() {
		if(NOT_NULL_BLANK_ZEROS == null){
		   NOT_NULL_BLANK_ZEROS = new PropertySelector() {
				public boolean include(Object value, String propertyName, Type type) {
					return value != null
							&& (((value instanceof String) && !("").equals(value)) 
									|| ((value instanceof Number) && ((Number) value).longValue() != 0));			
				}
			};
		}
		return NOT_NULL_BLANK_ZEROS;
	}

}



Criteria c = session.createCriteria(Student.class);
l = c.add(Example.create(s)
                 .setPropertySelector(

	            MyPropertySelector.getNotNullBlankZeros())

                 .enableLike()
).list()
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics