Session session = This.getsession ();
String hql = "from Tblfwxx FW where fw.title like?";
Query query = session.createquery (HQL);
Query.setstring (0, "% Yan er%");
Used above. " As a placeholder, and then set the value of the parameter one by one, using the SetString method of query. But this reduces the readability of the code.
So try to use "named parameter query" to solve these problems later
Replace the HQL statement above with the following: String hql = "from Tblfwxx FW where Fw.tltle like:zt";
Query query = session.createquery (HQL);
Query.setstring ("zt", "Yan Son");
=============================
I've also talked about criteria queries (also object queries)
The criteria object is mainly to encapsulate the query conditions and to provide restrictions and other categories for assistance. (For specific use, find network resources)
Example: Public List search (tblfwxx condition) {
Session session = This.getsession ();
Criteria C = Session.createcriteria (Tblfwxx.class);
if (null!= condition) {
if (condition.gettitle ()!= null &&!condition.gettitle (). Equals ("")) {
C.add (Restrictions.like) ("title", Condition.gettitle (), matchmode.anywhere);
}
}
}