@RequestMapping(method = RequestMethod.GET, produces = "application/json", value = "/searchbyname")
public
@ResponseBody
ResponseData searchByName(@RequestParam("name") String name, HttpServletRequest request) {
ResponseData responseData = new ResponseData();
try {
EntityManager em = MyEntityManagerFactory.getEm(request.getSession());
Query query = em.createQuery("SELECT t.name,t.displayName,t.description FROM TblEFromTemplateE t where t.name LIKE :name OR t.displayName LIKE :displayName" +
" OR t.description LIKE :description");
query.setParameter("name","%"+ name + "%");
query.setParameter("displayName","%"+ name + "%");
query.setParameter("description","%"+ name + "%");
List<Object[]> list = query.getResultList();
List<ResponseEFormTemplate> results = new ArrayList<ResponseEFormTemplate>();
for (Object[] template : list) {
ResponseEFormTemplate template1 = new ResponseEFormTemplate();
template1.setName((String)template[0]);
template1.setDisplayName((String)template[1]);
template1.setDescription((String)template[2]);
results.add(template1);
}
responseData.setSuccess(true);
responseData.setMax(results.size());
responseData.setData(results);
return responseData;
} catch (Exception exc) {
exc.printStackTrace();
return ResponseData.error(exc);
}