`

List.isEmpty

JDK 
阅读更多

jdk源码:

 

/**
     * Returns <tt>true</tt> if this list contains no elements.
     *
     * @return <tt>true</tt> if this list contains no elements
     */
    public boolean isEmpty() {
	return size == 0;
    }

 

 

应用场景:

 

public <T> T find(Class<T> $class, Date statTime, String businessType) {
	Session session = sessionFactory.getCurrentSession();
	Map<String, Object> properties = new HashMap<String, Object>();

	StringBuffer hql = new StringBuffer("from " + $class.getSimpleName() + " t where t.businessType = :businessType and t.statTime = :statTime ");

	properties.put("statTime", statTime);
	properties.put("businessType", businessType);

	Query query = session.createQuery(hql.toString());
	query.setProperties(properties);

	List<T> list = query.list();
	if (list.isEmpty()) {// 为空 代表这条数据不存在
		return null;
	} else {
		return list.get(0);
	}
}

 

分享到:
评论

相关推荐

    基于列表实现的元素迭代器算法(java算法源码)

    if (list.isEmpty())//若列表为空,则 nextPosition = null;//当前元素置空 else//否则 nextPosition = list.first();//从第一个元素开始 } //检查迭代器中是否还有剩余的元素 public boolean hasNext...

    Struts2 Spring hibernate 国际化 表单验证 安全退出

    这是之前分页的升级版 带国际化 表单验证 用户登录 安全退出 功能都实现了就是不太美观 开发环境 myeclipse6.0 jdk1.6 Tomcat6.0 sql2000 数据库也放到里面了 在db文件夹下 库文件不变 ... return list.isEmpty(); }

    scala-2.9.2.jar

    private def headOf(list:List[T]) = if (list.isEmpty) func.zero else list.head private def tailOf(list:List[T]) = if (list.isEmpty) Nil else list.tail def isZero = cell == func.zero def execute(ch:...

    对DAO编写单元测试源代码

    if(list.isEmpty()) return false; HibernateUtil.executeUpdate( "delete from PasswordTicket as pt where pt.user=?", new Object[] { user } ); HibernateUtil.executeUpdate( ...

    csci374-sp21-lab4-baboomerang:GitHub Classroom创建的csci374-sp21-lab4-baboomerang

    允许的库函数: List.head , List.tail , List.isEmpty 问题1 编写一个递归函数prod: (lst:int list) -&gt; int ,该函数返回整数列表中元素的乘积。 问题2 编写一个递归函数map: (f:(int -&gt; 'a) -&gt; int list -&gt; '...

    LinearList.zip

    bool IsEmpty() const { return length == 0; }//判断线性表是否为空 int Length() const { return length; }//返回数组长度 void SetLength(int SetLength) { length = SetLength; }//设置数组长度 int MaxSize...

    基于Java的二叉树层序遍历打印实现.docx

    二叉树层序遍历Ⅰ——剑指offer32-Ⅰ ...q.isEmpty()) { TreeNode node = q.poll(); list.add(node.val); if (node.left != null) q.add(node.left); if (node.right != null) q.add(node.right); }

    简单的搜索控件 小demo

    适合新手使用 代码片段: public class MainActivity extends Activity implements... if (TextUtils.isEmpty(newText)) { list.clearTextFilter(); } else { list.setFilterText(newText); } return true; } }

    达内 coreJava 习题答案

    1,编写程序,判断给定的某个年份是否是闰年。 闰年的判断规则如下: (1)若某个年份能被4整除但不能被100整除,则是闰年。 (2)若某个年份能被400整除,则也是闰年。 import java.util.Scanner;...

    02_SpringCloud客户端负载均衡Ribbon.md

    if(StringUtils.isEmpty(serverurl)){ return "请求列表为null"; } System.out.println("请求服务地址:"+serverurl); return restTemplate.getForObject(serverurl,String.class); } private ...

    线性表list_array的源代码(c语言)

    int list_isempty(struct list *list); void list_clear(struct list *list); int list_count(struct list *list); int list_get(struct list *list, int index); int list_remove(struct list *list, int index); ...

    Android中使用Gson解析JSON数据的两种方法

    第二种类型是序列(sequence),也就是若干个相关的数据按照一定顺序并列在一起,又叫做数组(array)或列表(List),比如”北京,上海”。 第三种类型是映射(mapping),也就是一个名/值对(Name/value),即...

    springboot jpa mysql controller演示

    List&lt;User&gt; users = userRepository.findAll(); modelMap.put("users", users); return "jpatest"; } /** * 输出字符串测试 * http://localhost:8080/helloboot * @return */ @RequestMapping("/...

    自定义Dialog弹窗

    public Builder setContent(List&lt;String&gt; contents) { dialog.mContents = contents; return this; } /** * 单条提示 */ public Builder setContent(String content) { dialog.mContent = content; ...

    java树形结构递归查询

    if (CollectionUtils.isEmpty(list)) { return categoryTree; } for (CategoryDO categoryDO : list) { allDTOList.add(new CategoryTreeDTO().convertDOToDTO(categoryDO)); } //当前等级类目 category...

    Java Oracle分页处理

    List&lt;PageBean&gt; list = new ArrayList(); newgetResouce newgetresouce = new newgetResouce(); //通过显示页面传递一个pagetype对象和PaginationBean对象 Page page = new Page(request.getParameter(...

    下载excel表格工具类

    try {List,Object&gt;&gt; listLog = maintainlogService.selectListByDownload(memberId,date,keyword);//查询数据库中的数据 //excel数据 List&lt;Object&gt; listData = new ArrayList&lt;Object&gt;(); if (null ...

    HTML5画布Signature_Pad.zip

    用 Bézier 曲线进行插补,使线条更平滑...signaturePad.isEmpty(); // Unbinds all event handlers signaturePad.off(); // Rebinds all event handlers signaturePad.on(); 标签:Signature

    QQ聊天程序源码

    sendText.isEmpty()) { QString windowTitle = this-&gt;windowTitle().replace("].",""); QString toId = QString(windowTitle.split("[").at(1)); QString msgType = "MSG_CLIENT_CHAT"; QByteArray block; ...

    Java基于列表实现(无序)词典结构(算法源码)

    List list = new List_DLNode(); Iterator P = L.positions(); while (P.hasNext()) { Position pos = (Position)P.getNext(); Entry entry = (EntryDefault) pos.getElem(); if (T.isEqualTo(entry....

Global site tag (gtag.js) - Google Analytics