如何使collection查询结果为空时,不显示该字段
来源:5-10 mybatis三剑客之mybatis-generator生成数据对象和时间戳优化
Bearxsh
2019-04-22
配置文件:
<?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.farmplus.agriculture.dao.ProductCategoryDao">
<resultMap id="menuMap"
type="com.farmplus.agriculture.dto.ProductCategoryList">
<id column="product_category_id" property="value" />
<result column="product_category_name" property="label"/>
<collection column="product_category_id" property="children"
ofType="com.farmplus.agriculture.dto.ProductCategoryList" select="getProductCategoryList" />
</resultMap>
<select id="getProductCategoryList" parameterType="java.math.BigInteger"
resultMap="menuMap">
SELECT * from product_category where parent_id = #{value}
</select>
</mapper>
返回json数据
{
"code": 200,
"options": [
{
"value": 1,
"label": "水果",
"children": [
{
"value": 5,
"label": "甜瓜",
"children": [
{
"value": 14,
"label": "绿宝甜瓜",
"children": []
},
{
"value": 15,
"label": "黄金甜瓜",
"children": []
}
]
},
{
"value": 6,
"label": "西瓜",
"children": [
{
"value": 16,
"label": "黑美人西瓜",
"children": []
},
{
"value": 17,
"label": "甜王西瓜",
"children": []
}
]
},
{
"value": 7,
"label": "油桃",
"children": []
}
]
},
{
"value": 3,
"label": "蔬菜",
"children": [
{
"value": 8,
"label": "黄瓜",
"children": [
{
"value": 18,
"label": "密刺黄瓜",
"children": []
},
{
"value": 19,
"label": "旱黄瓜",
"children": []
}
]
},
{
"value": 9,
"label": "土豆",
"children": []
},
{
"value": 10,
"label": "西红柿",
"children": []
}
]
},
{
"value": 4,
"label": "水产",
"children": [
{
"value": 11,
"label": "小龙虾",
"children": []
},
{
"value": 12,
"label": "螃蟹",
"children": [
{
"value": 20,
"label": "花蟹",
"children": []
},
{
"value": 21,
"label": "关公蟹",
"children": []
},
{
"value": 22,
"label": "孟加拉蟹",
"children": []
}
]
},
{
"value": 13,
"label": "生蚝",
"children": []
}
]
}
],
"message": "成功"
}
问题:
写回答
1回答
-
geelylucky
2019-04-22
同学,你好,这个跟json格式化有关系的,老师在二期的时候专门讲过相关的设置。其实不处理也没有关系的。这里是老师二期的课程:https://coding.imooc.com/learn/list/162.html
042019-04-23
相似问题