1.条件查询的两种方式
方案1:设置查询条件通过EntityWrapper-不能返回关联对象
方案2:自己写sql,还能返回关联对象
controller
service
mapper
mapper.xml
<sql id="whereSql">
<where>
<if test="keyword!=null and keyword!=''">
and t.companyName like concat('%',#{keyword},"%")
</if>
</where>
</sql>
<!--List<Tenant> loadPageList(Page<Tenant> page, TenantQuery query);-->
<select id="loadPageList" resultMap="TenantMap">
SELECT
t.*, type.id tid,
type. NAME tname,
e.id eid,e.realName
FROM
t_tenant t
LEFT JOIN t_tenant_type type ON t.tenant_type = type.id
LEFT JOIN t_employee e on t.admin_id = e.id
<include refid="whereSql"></include>
</select>
2.@TableField注释
数据库里面是没有关联属性,只是用来显示或接受值时后就时候这个注解
比如:
@TableField(exist = false)
private TenantType type;