原因有时实体类属性不够用,又不想写自定义VO了,所以用map,这样直接返回前台用起来也很方便
1 mapper.xml
注意是resultType 不是resultMap 否则报错
<select id="getOrder" parameterType="hashMap" resultType="java.util.Map">
SELECT * FROM order
<where>
<if test="orderId != null and orderId != ''"> and order_id = #{orderId}</if>
</where>
</select>
2 mapper.java
List<Map<String, Object>> getOrder(Map<String,Object> map);
3 service 组装查询条件
public List<Map<String, Object>> getOrder(String storeId) {
Map<String,Object> map=new HashMap<String,Object>();
map.put("orderId",orderId);
return storeApiOrderMapper.getOrder(map);
}