代码演示

图:order by c、CustomerVo、private Cu 的流程。

图:private Cu、order by c、CustomerVo 的流程。

图:order by c、private Cu、CustomerVo 的层次。

1
2
3
4
5
CustomerVo实体类(检索条件类)
private Customer customer;
private Date startDate;
private Date endDate;
private List<Integer> ids;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<resultMap type="customer" id="customerDictMap" autoMapping="true">

<association property="custSource" javaType="BaseDict" autoMapping="true">
<!-- column="sid"代表的是数据库表的列(别)名
property="dict_id代表的类的字段名(这里是驼峰设置了)
-->
<id column="sid" property="dict_id"/>
<result column="sname" property="dict_item_name"/>
</association>

<association property="custIndustry" javaType="BaseDict" autoMapping="true">
<id column="iid" property="dict_id"/>
<result column="iname" property="dict_item_name"/>
</association>

<association property="custLevel" javaType="BaseDict" autoMapping="true">
<id column="lid" property="dict_id"/>
<result column="lname" property="dict_item_name"/>
</association>

</resultMap>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<select id="queryCustomers" parameterType="CustomerVo" resultMap="customerDictMap">
select c.*,ds.dict_item_name sname,ds.dict_id sid,
di.dict_item_name iname,di.dict_id iid,
dl.dict_item_name lname,dl.dict_id lid
from cst_customer c,base_dict ds,base_dict di, base_dict dl
where c.cust_source=ds.dict_id and
c.cust_industry=di.dict_id and
c.cust_level=dl.dict_id

<if test="customer !=null">
<!-- test里面的内容是实体类的字段值及属性 -->

<if test="customer.custName !=null and
customer.custName !=''">

and c.cust_name like '%${customer.custName}%'
</if>

<if test="customer.custIndustry != null and customer.custIndustry.dict_id != null and
customer.custIndustry.dict_id != ''">

and c.cust_industry = #{customer.custIndustry.dict_id}
</if>
</if>

<if test="startDate != null">
and c.cust_createDate >= #{startDate}
</if>
<if test="endDate != null">
<!--注意这里的小于号不是<,而是&lt;代替-->
and c.cust_createDate &lt;= #{endDate}
</if>
order by c.cust_id desc
</select>