多表联合查询需要自己写 :
在mapper.xml中
<sql id="Base_Column_List_with_other">
a.id, a.csid, a.desc,a. image, a.is_hot, a.market_price, a.pdate, a.shop_price, a.title,b.one,b.two,b.three
</sql>
<select id="selectByExampleWithOther" parameterType="com.wj.bean.ProductExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from table1 a
left join table2 b on a.id = b.id
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
如果要对返回结果进行封装
这里需要注意的是要在bean的封装中加入另一个对象的get和set
<resultMap id="BaseResultMapWithOther" type="com.wj.bean.Product">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="csid" jdbcType="INTEGER" property="csid" />
<result column="desc" jdbcType="VARCHAR" property="desc" />
<result column="image" jdbcType="VARCHAR" property="image" />
<result column="is_hot" jdbcType="INTEGER" property="isHot" />
<result column="market_price" jdbcType="DOUBLE" property="marketPrice" />
<result column="pdate" jdbcType="TIMESTAMP" property="pdate" />
<result column="shop_price" jdbcType="DOUBLE" property="shopPrice" />
<result column="title" jdbcType="VARCHAR" property="title" />
<association property="ProductUser" javaType="com/wj/bean/User.java">
<id column="你在xml中起的名字" jdbcType="INTEGER" property="表中的真实字段" />
<result column="xml中起的名字比如" jdbcType="INTEGER" property="表中的真实字段" />
<result column="xml中起的名字比如" jdbcType="VARCHAR" property="表中的真实字段" />
</association>
</resultMap>
Spring Test模块
首先导入依赖
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.4.RELEASE</version>
<scope>test</scope>
</dependency>
然后添加注解
sqlSession批量操作