zoukankan      html  css  js  c++  java
  • ssh框架下 写简单的hql语句

    author: myzhai

    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方法,接口等
  • 相关阅读:
    模型定义
    聚合、原生和子查询
    PHP curl扩展
    时间查询
    查询表达式
    HTTP协议的Keep-Alive 模式
    抽象类可以没有抽象方法
    Nginx解决前端跨域问题,Nginx反向代理跨域原理
    Nginx配置文件不生效,Nginx配置文件重启也不生效
    php openssl加密解密函数
  • 原文地址:https://www.cnblogs.com/wisdombud/p/7157433.html
Copyright © 2011-2022 走看看