zoukankan      html  css  js  c++  java
  • Spring+Hibernate系列教材 (四)- 条件查询

    使用HibernateTemplate进行模糊查询 
    其思路和直接使用hibernate有所区别

    步骤1:模糊查询

    步骤 1 : 模糊查询

    分别使用Hql和Criteria进行模糊查询

    package com.how2java.test;

       

    import java.util.List;

      

    import org.hibernate.criterion.DetachedCriteria;

    import org.hibernate.criterion.Restrictions;

    import org.springframework.context.ApplicationContext;

    import org.springframework.context.support.ClassPathXmlApplicationContext;

      

    import com.how2java.dao.CategoryDAO;

    import com.how2java.pojo.Category;

       

    public class TestSpring {

       

        public static void main(String[] args) {

            ApplicationContext context = new ClassPathXmlApplicationContext(

                    new String[] { "applicationContext.xml" });

            CategoryDAO dao = (CategoryDAO) context.getBean("dao");

              

            List<Category> cs =dao.find("from Category c where c.name like ?""%c%");

      

            for (Category c : cs) {

                System.out.println(c.getName());

            }

      

            DetachedCriteria dc = DetachedCriteria.forClass(Category.class);

            dc.add(Restrictions.like("name""%分类%"));

            cs =dao.findByCriteria(dc);

      

            for (Category c : cs) {

                System.out.println(c.getName());

            }

              

        }

    }


    更多内容,点击了解: https://how2j.cn/k/spring-hibernate/spring-hibernate-criterion/104.html

  • 相关阅读:
    小学二年级四则运算软件需求规格说明书
    周活动总结
    构建之法阅读笔记01
    学习进度条01
    四则运算
    软件工程概论
    课后作业1
    继承与多态-课后作业
    python文件处理-将图像根据坐标画矩形标记
    python文件处理-将图像根据坐标切割成若干小图
  • 原文地址:https://www.cnblogs.com/Lanht/p/12789355.html
Copyright © 2011-2022 走看看