您的位置:首页 > 数据库

Hql传中文参数出现乱码(同sql传中…

2014-06-05 16:04 148 查看
可以在spring配置文件中配置: [html] view
plaincopyprint?<</SPAN>property name="hibernateProperties">      <</SPAN>props>          <</SPAN>prop key="hibernate.dialect">${hibernate.dialect}</</SPAN>prop>          <</SPAN>prop key="hibernate.show_sql">${hibernate.show_sql}</</SPAN>prop>          <</SPAN>prop key="connection.autocommit">false</</SPAN>prop>          org.hibernate.hql.classic.ClassicQueryTranslatorFactory可以在hibernate.cfg.xml中配置: [html] view
plaincopyprint?<</SPAN>property name="hibernate.query.factory_class">        org.hibernate.hql.classic.ClassicQueryTranslatorFactory  </</SPAN>property>  
或者在写HQL的时候不吧中文参数拼凑进去,用query的setXxx。   setProperties()方法  个人觉得这个跟ORM技术的ibatis中的SQLMAP有些许相似。它是用setProperties()方法。如:String hql 
=   " from Customer user where 1=1 and userr.mc like :sna
" ;
Customer cus 
=   new  Customer();
cus.setMc(
" 惠止南国 "
);
Session session 
=  getHibernateTemplate().getSessionFactory().openSession();
Transaction tx 
=  session.beginTransaction();
List returnList 
=  session.createQuery(sql).setProperties(cus).list();
tx.commit();
session.close();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: