生产上面那个sql的mapper.xml 格式
时间: 2023-12-03 08:02:16 浏览: 80
Sure! Here's an example of how you can write the corresponding mapper XML file for the given SQL query:
```xml
<!-- adminMapper.xml -->
<mapper namespace="com.example.admin.mapper.AdminMapper">
<resultMap id="adminResultMap" type="com.example.admin.model.Admin">
<!-- Specify the column mappings for the result fields -->
<result column="id" property="id" />
<result column="name" property="name" />
<!-- Add mappings for other columns in the t_admin table -->
<!-- Additional result field mappings for the role information -->
<result column="rid" property="roleId" />
<result column="rname" property="roleName" />
<result column="rnameZh" property="roleNameZh" />
</resultMap>
<select id="getAdminsWithRole" resultMap="adminResultMap">
SELECT
a.*,
r.id AS rid,
r.`name` AS rname,
r.nameZh AS rnameZh
FROM
t_admin a
LEFT JOIN t_admin_role ar ON a.id = ar.adminId
LEFT JOIN t_role r ON r.id = ar.rid
WHERE
a.id != 1
AND a.`name` LIKE '%华%'
ORDER BY
a.id
</select>
</mapper>
```
In this example, the mapper XML file is named `adminMapper.xml`, and it defines a namespace for the `AdminMapper` interface. It also includes a `resultMap` element to map the columns from the `t_admin` table to the corresponding fields in the `Admin` model class.
The `select` statement with the id `getAdminsWithRole` corresponds to the SQL query provided. The `resultMap` attribute is set to the `adminResultMap` defined earlier to map the query results to the `Admin` model class.
Please note that you may need to adjust the column names, model class names, and package names in the XML file based on your specific application's requirements.
阅读全文