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

  • 相关阅读:
    动手动脑之异常处理
    git一些概念
    jquery each函数使用
    数据库客户端
    plotly.js
    网站跳转汇总
    jquery 实现间隔运行
    学习 在线调试
    Robot限制字典的key大写的class
    Gerrit 相关
  • 原文地址:https://www.cnblogs.com/Lanht/p/12789355.html
Copyright © 2011-2022 走看看