话不多少,且看代码。
@RestController
@RequestMapping("/integration/regions")
@Api(tags = "地区集成接口")
public class ItegrationRegionController {
@Resource
private RegionQuery regionQuery;
@GetMapping("/{id}")
@ApiOperation("获取地区列表-通过父ID")
public RegionTreeVO regionTree(@PathVariable String id) {
return regionQuery.getRegionTree(id);
}
}
@Repository
@Transactional(readOnly = true)
public class RegionQuery {
@Resource
private RegionQueryDAO regionQueryDAO;
public RegionTreeVO getRegionTree(String pid) {
return regionQueryDAO.findRegionTreeById(pid);
}
}
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "地区树")
public class RegionTreeVO {
private String id;
private String name;
private Boolean isLeaf;
private List<RegionTreeVO> children;
}
public interface RegionQueryDAO {
RegionTreeVO findRegionTreeById(@Param("regionId") String regionId);
}
<resultMap id="RegionTreeResultMap" type="com.comall.dc.region.controller.vo.RegionTreeVO">
<id column="id" property="id"/>
<result column="region_name" property="name"/>
<result column="is_leaf" property="isLeaf"/>
<collection property="children" ofType="com.comall.dc.region.controller.vo.RegionTreeVO" column="id"
select="findRegionTreeChildrenByPid"/>
</resultMap>
<select id="findRegionTreeById" resultMap="RegionTreeResultMap">
SELECT
a.id,
a.region_name,
0 AS is_leaf
FROM dc_region a
WHERE a.id = #{regionId}
</select>
<select id="findRegionTreeChildrenByPid" resultType="com.comall.dc.region.controller.vo.RegionTreeVO">
SELECT
a.id,
a.region_name AS name,
0 AS isLeaf
FROM dc_region a
WHERE a.pid = #{id}
</select>
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.jianshu.com/p/daf0f5851baa