简单的hql
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了简单的hql相关的知识,希望对你有一定的参考价值。
### ssh框架下 写简单的hql语句
##简单的hql 重要的在dao层 !!!
---
>* action
```
@Autowired
private FlowActiveSrv flowActiveSrv;
private Integer pageSize;
private String findUserId() {
UserSession userSession = (UserSession) session.get("UserSession");
return userSession.getId();
}
//此处返回的是一个List<FlowActive>集合
public void findMyApply() {
String userId = this.findUserId();
List<FlowActive> list =this.flowActiveSrv.findMyApply(userId, pageSize);
this.sendResponseMsg(list);
}
//处理一下
protected void sendResponseMsg(Object src) {
final Gson g = new GsonBuilder().setDateFormat(DateFormat.DateTime.getFormat()).create();
this.sendResponseMsg(g.toJson(src));
}
```
>* serviseImpl
```
@Autowired
private FlowActiveDao flowActiveDao;
@Override
public List<FlowActive> findMyApply(String userId,int pageSize) {
return flowActiveDao.findMyApply(userId,pageSize);
}
```
>* daoImpl
```
@Override
public List<FlowActive> findMyApply(String userId,int pageSize) {
if (StringUtils.isBlank(userId)) {
return Lists.newArrayList();
}
Map<String, Object> values = new HashMap<String, Object>();
String hql = "FROM FlowActive where step != 99 and applyPersonId = :applyPersonId order by createTime desc";
values.put("applyPersonId", userId);
Query query = createHqlQuery(hql, values);
query.setFirstResult(0);
query.setMaxResults(pageSize);
@SuppressWarnings("unchecked")
List<FlowActive> list = query.list();
return list.isEmpty() ? Lists.newArrayList() : list;
}
```
>* js 调用方法后台 填充模板
```
//这里使用的模板填充 template.js
// http://www.cnblogs.com/shiyou00/p/6841801.html
//http://www.jq22.com/jquery-info1097
function loadApplyData() {
$.post(applyAction + "!findMyApply", { pageSize: 5 }, function(data) {
var html = template("gridApplyTpl", { ‘results‘: data });
$("#gridApplyBody").html(html);
}, "json")
}
```
>* 以上代码尚未贴出get,set方法,接口等
以上是关于简单的hql的主要内容,如果未能解决你的问题,请参考以下文章