私は春3.0を使用しており、JqGridプラグインを使用しています。私はすべての検索条件でjson文字列を送信する検索機能に取り組んでいます。文字列は次のようになります。Hibernate criteria queries - クエリ条件
{"groupOp":"AND","rules":[{"field":"firstName","op":"bw","data":"John"},{"field":"lastName","op":"cn","data":"Doe"},{"field":"gender","op":"eq","data":"Male"}]}
あなたはルール配列内の「OP」プロパティを見ると、あなたが実行しなければならない操作が表示されます。 Jqグリッドには以下の操作があります。
['eq'、 'ne'、 'lt'、 'le'、 'gt'、 'ge'、 'bw'、 'bn'、 'in' NI」、 'EW'、 'EN'、 'CN'、 'NC等しい ' '等しくない'、 '以下'、 '以下'']
【に対応
'、 「より大きい」、「より大きい」、「より大きい」、「始まる」、「始まる」、「入っている」、「入っていない」、「終わる」、「終わらない」、私は検索機能を有効にするには、検索休止基準を使用する予定
]が含まれていません。このため私はジャックのObjectMapperを使用して、着信JSONをJavaに変換しています。これはすべてうまくいいです。ここにjsonを変換するコードがあります。
public class JsonJqgridSearchModel {
public String groupOp;
public ArrayList<JqgridSearchCriteria> rules;
}
public class JqgridSearchCriteria {
public String field;
public String op;
public String data;
public SimpleExpression getRestriction(){
if(op.equals("cn")){
return Restrictions.like(field, data);
}else if(op.equals("eq")){
return Restrictions.eq(field, data);
}else if(op.equals("ne")){
return Restrictions.ne(field, data);
}else if(op.equals("lt")){
return Restrictions.lt(field, data);
}else if(op.equals("le")){
return Restrictions.le(field, data);
}else if(op.equals("gt")){
return Restrictions.gt(field, data);
}else if(op.equals("ge")){
return Restrictions.ge(field, data);
}else{
return null;
}
}
}
@RequestMapping(value = "studentjsondata", method = RequestMethod.GET)
public @ResponseBody String studentjsondata(@RequestParam("_search") Boolean search ,HttpServletRequest httpServletRequest) {
StringBuilder sb = new StringBuilder();
Format formatter = new SimpleDateFormat("MMMM dd, yyyy");
if(search){
ObjectMapper mapper = new ObjectMapper();
try {
JsonJqgridSearchModel searchModel= mapper.readValue(httpServletRequest.getParameter("filters"), JsonJqgridSearchModel.class);
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
Criteria criteria = session.createCriteria(Person.class);
Iterator<JqgridSearchCriteria> iterator = searchModel.rules.iterator();
while(iterator.hasNext()){
System.out.println("before");
criteria.add(iterator.next().getRestriction());
System.out.println("after");
}
} catch (JsonParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}else{//do other stuff here}
ここで問題が発生します。jqGrid操作をequivelent hibernateコマンドにどのように変換すればよいですか?たとえば について「CN」は
criteria.add(Restrictions.like("firstName", myJsonJqgridSearchModel.data));
私はいくつかの編集を行いました。上記は私の現在のコードを反映していますが、これを行う良い方法はありますか? – Binaryrespawn