Authored by mlge

no message

package com.model;
import lombok.Data;
/**
* Created by craig.qin on 2017/6/26.
*/
@Data
public class DashboardPortal {
private int id;
private String text;
private String link;
private String topType;
private String secondType;
private int seqNo;
}
... ...
package com.monitor.mysql.mapper;
import com.model.DashboardPortal;
import java.util.List;
/**
* Created by craig.qinchao on 2017/06/29.
*/
public interface DashboardPortalMapper {
List<DashboardPortal> selectAll();
}
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.monitor.mysql.mapper.DashboardPortalMapper" >
<resultMap id="BaseResultMap" type="com.model.DashboardPortal" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="text" property="text" jdbcType="VARCHAR" />
<result column="link" property="link" jdbcType="VARCHAR" />
<result column="toptype" property="topType" jdbcType="VARCHAR" />
<result column="secondtype" property="secondType" jdbcType="VARCHAR" />
<result column="seq_no" property="seqNo" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, text,link,toptype,secondtype,seq_no
</sql>
<select id="selectAll" resultMap="BaseResultMap">
select * from dashboard_portal order by seq_no
</select>
</mapper>
\ No newline at end of file
... ...
package com.monitor.other.dashboardportal;
import com.alibaba.fastjson.JSON;
import com.model.DashboardPortal;
import com.monitor.model.response.BaseResponse;
import com.monitor.mysql.mapper.DashboardPortalMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
@Controller
@RequestMapping("/dashboardPortal")
public class DashboardPortalCtrl {
@Autowired
private DashboardPortalMapper dashboardPortalMapper;
@RequestMapping("/queryAll")
@ResponseBody
public BaseResponse queryAll(){
List<DashboardPortal> portals=dashboardPortalMapper.selectAll();
// Map<String,List<DashboardPortal>> map=new LinkedHashMap<>();
Map<String,Map<String,List<DashboardPortal>>> map=new LinkedHashMap<>();
if(portals!=null&&portals.size()>0){
for(DashboardPortal portal:portals){
String firstType=portal.getTopType();
if(!map.keySet().contains(firstType)){
map.put(firstType,new LinkedHashMap<>());
}
String secondType=portal.getSecondType();
if(!map.get(firstType).keySet().contains(secondType)){
map.get(firstType).put(secondType,new ArrayList<>());
}
map.get(firstType).get(secondType).add(portal);
}
}
BaseResponse res= new BaseResponse() ;
res.setData(map);
return res;
}
}
... ...