当前位置 : 主页 > 编程语言 > java >

list一对多循环查询

来源:互联网 收集:自由互联 发布时间:2021-06-28
适用于一个属性下关联多个字段的查询,以及在页面上的追加 //接口 public String carFieldMoreDetail(Map mapStr) throws Exception {Map mapSqlParameter = new HashMap (); StringBuffer sql = new StringBuffer(); Gson gson
适用于一个属性下关联多个字段的查询,以及在页面上的追加
//接口
    public String carFieldMoreDetail(Map
 
   mapStr) throws Exception {
		Map
  
    mapSqlParameter = new HashMap
   
    (); StringBuffer sql = new StringBuffer(); Gson gson = new Gson(); sql.append("SELECT ca.class_name,ca.class_id FROM car_attribute_class ca LEFT OUTER JOIN car_attribute c ON ca.class_id = c.class_id"); sql.append(" LEFT OUTER JOIN car_attribute_join cj ON c.attribute_id = cj.attribute_id WHERE cj.car_id = :car_id GROUP BY ca.class_name"); mapSqlParameter.put("car_id", mapStr.get("car_id")); List
    
     > list_Map = this.gyDaoImpl.findSqlList(sql, mapSqlParameter); for(Map
     
       map:list_Map){ String class_id=UtilStr.getStr(map.get("class_id")); sql.delete(0, sql.length()); sql.append("SELECT caj.car_id,ca.attribute_id,ca.attribute_name,ca.attribute_icon,caj.car_id,caj.join_val,cc.class_name"); sql.append(" FROM car_attribute ca LEFT OUTER JOIN car_attribute_join caj ON caj.attribute_id = ca.attribute_id LEFT OUTER JOIN car_attribute_class cc ON ca.class_id = cc.class_id"); sql.append(" WHERE caj.car_id =:car_id AND cc.class_id=:class_id "); mapSqlParameter.put("class_id",class_id); mapSqlParameter.put("car_id", mapStr.get("car_id")); map.put("attributeList", this.gyDaoImpl.findSqlList(sql, mapSqlParameter)); } String data = gson.toJson(list_Map); return UtilStr.return_list("获取成功", "", data); } //jquery function getCarFieldDetail(id){ var jsonObj = { "car_id" : id } var jsonAjax = { "url" : "app_new_car_more_field_detail.do", "jsonData" : jsonObj, "methodName" : "getCarFieldDetailBack" } getAjaxData(jsonAjax); } /** * 回调 * @param {Object} jsonObj */ function getCarFieldDetailBack(jsonObj){ var jsoninfo = strToJson(jsonObj.data); var arr = strToJson(jsoninfo.data); var content=''; $.each(arr, function(e,obj) { content+='
      
  • '+obj.class_name+'
  • '; var arrey = obj.attributeList; $.each(arrey, function(i,lbj) { content+='
  • '+lbj.attribute_name+''+lbj.join_val+'
  • '; }); content+='
'; }); $("#filed_list").append(content); mui.init(); mui('.mui-scroll-wrapper').scroll(); }
网友评论