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方法,接口等
  • 相关阅读:
    vue hover如何触发事件?
    防止 window.open 被拦截
    input输入框change和blur事件区别
    神马?使用JS直接上传并预览粘贴板的图片?
    删除设备与驱动器中百度网盘图标
    枚举类字典代码 草稿
    中文转换成阿拉伯数字
    Java对象与类中的一个小练习
    正向代理和反向代理
    MySQL教程126-MySQL事务隔离级别
  • 原文地址:https://www.cnblogs.com/wisdombud/p/7157433.html
Copyright © 2011-2022 走看看