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
|
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd"> <mapper namespace="com.xiang.mapper.UserMapper"> <!-- 嵌套结果 --> <resultMap type="com.xiang.domain.User" id="UserResultMap"> <id property="id" column="userId" jdbcType="INTEGER" javaType="java.lang.Integer"/> <result property="name" column="name" jdbcType="VARCHAR" javaType="java.lang.String"/> <result property="gender" column="gender" jdbcType="INTEGER" javaType="java.lang.Integer"/> <result property="age" column="age" jdbcType="INTEGER" javaType="java.lang.Integer"/> <association property="address" javaType="com.xiang.domain.Address"> <id property="id" column="id" jdbcType="INTEGER" javaType="java.lang.Integer"/> <result property="province" column="province" jdbcType="VARCHAR" javaType="java.lang.String"/> <result property="city" column="city" jdbcType="VARCHAR" javaType="java.lang.String"/> <result property="district" column="district" jdbcType="VARCHAR" javaType="java.lang.String"/> <result property="detail" column="detail" jdbcType="VARCHAR" javaType="java.lang.String"/> </association> </resultMap>
<select id="findById" parameterType="int" resultMap="UserResultMap"> SELECT u.id userId,u.name,u.gender,u.age,a.id,a.province,a.city,a.district,a.detail FROM user u LEFT JOIN address a on u.addressId = a.id where u.id = #{id} </select>
<select id="findAll" parameterType="int" resultMap="UserResultMap"> SELECT u.id userId,u.name,u.gender,u.age,a.id,a.province,a.city,a.district,a.detail FROM user u LEFT JOIN address a on u.addressId = a.id </select> </mapper>
|
近期评论