Criteria criteria = session.createCriteria(objectName.class);
criteria.add(Expression.like("attributeName", "%aaa%");criteria.list();

解决方案 »

  1.   

    怎样把变量(attrubuteValue)传进去?
      

  2.   

    criteria.add(Expression.like("attributeName", "%aaa%");
    那个aaa不就是你要传的参数吗?这个不用传
    criteria.add以后就有了
      

  3.   

    "from objectName o where o.attributeName like '%"+attrubuteValue+"%'"
      

  4.   

    String sql = "from objectName o where o.attributeName=:attrubuteValue";Query query = session.createQuery();
    query.setString("attributeValue","%aa%");
      

  5.   

    另外
    "from objectName o where o.attributeName like '%"+attrubuteValue+"%'"
    这种写法是不安全的,如果attributeValue的值是 ' or 1=1 or 'a' like ' 的话就把所有的纪录全查出来了。而且有些值还可能破坏你的系统,比如调用数据库的函数之类。