如果用if语句写判断,然后根据判断添加查询条件是不是只能写成
if (request.getParameter("white") != null){
sql += "and white = '" + request.getParameter("white") +"'";}形式,而不能写成if (request.getParameter("white") == "2"){
//sql += "and white< 2.00000";}形式。为什么
第ä¸ç§æ¹å¼ï¼HQLï¼Hibernate Query Langugeï¼Hibernate æ¥è¯¢è¯è¨ï¼æ¥è¯¢
æ¯ä¸ç§é¢å对象çæ¥è¯¢è¯è¨ï¼å ¶ä¸æ²¡æ表åå段çæ¦å¿µï¼åªæç±»ã对象åå±æ§çæ¦å¿µï¼HQL æ¯åºç¨è¾ä¸ºå¹¿æ³çæ¹å¼
è¯æ³ï¼[select/update/deleteâ¦â¦] from Entity [whereâ¦â¦] [group byâ¦â¦] [havingâ¦â¦] [order byâ¦â¦]
(1).没使ç¨Springæ¡æ¶çåæ³ï¼
使ç¨HQLéè¦åæ¥
å¾å°Sessionãç¼åHQLè¯å¥ãå建Query对象ï¼Queryæ¥å£æ¯HQL æ¥è¯¢æ¥å£ãå®æä¾äºåç§çæ¥è¯¢åè½ï¼ãæ§è¡æ¥è¯¢ï¼å¾å°ç»æ
sessionFactory =
new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
String hql = âfrom Streetâ;
Query query = session.createQuery(hql);
List<Street> list = query.list();
(2).使ç¨Springæ¡æ¶çåæ³ï¼
String queryString = "select form entity ....";
List list=getHibernateTemplate().find(queryString);
第äºç§æ¹å¼ï¼Criteria æ¥è¯¢
Criteria æ¥è¯¢éç¨é¢å对象æ¹å¼å°è£ æ¥è¯¢æ¡ä»¶ï¼å称为对象æ¥è¯¢ï¼
å°±æ¯å¯¹SQL è¯å¥è¿è¡å°è£ ï¼éç¨å¯¹è±¡çæ¹å¼æ¥ç»ååç§æ¥è¯¢æ¡ä»¶
ç±Hibernate èªå¨äº§çSQL æ¥è¯¢è¯å¥
æ¯ä¸ç§é¢å对象çæ¥è¯¢è¯è¨ï¼å ¶ä¸æ²¡æ表åå段çæ¦å¿µï¼åªæç±»ã对象åå±æ§çæ¦å¿µï¼HQL æ¯åºç¨è¾ä¸ºå¹¿æ³çæ¹å¼
è¯æ³ï¼[select/update/deleteâ¦â¦] from Entity [whereâ¦â¦] [group byâ¦â¦] [havingâ¦â¦] [order byâ¦â¦]
(1).没使ç¨Springæ¡æ¶çåæ³ï¼
使ç¨HQLéè¦åæ¥
å¾å°Sessionãç¼åHQLè¯å¥ãå建Query对象ï¼Queryæ¥å£æ¯HQL æ¥è¯¢æ¥å£ãå®æä¾äºåç§çæ¥è¯¢åè½ï¼ãæ§è¡æ¥è¯¢ï¼å¾å°ç»æ
sessionFactory =
new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
String hql = âfrom Streetâ;
Query query = session.createQuery(hql);
List<Street> list = query.list();
(2).使ç¨Springæ¡æ¶çåæ³ï¼
String queryString = "select form entity ....";
List list=getHibernateTemplate().find(queryString);
第äºç§æ¹å¼ï¼Criteria æ¥è¯¢
Criteria æ¥è¯¢éç¨é¢å对象æ¹å¼å°è£ æ¥è¯¢æ¡ä»¶ï¼å称为对象æ¥è¯¢ï¼
å°±æ¯å¯¹SQL è¯å¥è¿è¡å°è£ ï¼éç¨å¯¹è±¡çæ¹å¼æ¥ç»ååç§æ¥è¯¢æ¡ä»¶
ç±Hibernate èªå¨äº§çSQL æ¥è¯¢è¯å¥
温馨提示:答案为网友推荐,仅供参考