ResultMap映射
<!-- 映射 --><resultMap id="clazzTimesMap" type="com.cskaoyan.bean.one2more.Clazz"><id column="id" property="id"/><result column="name" property="name"/><!--collection : 如果引用类型是一个集合,那么我们就使用 collection标签ofType: 集合里面元素的类型select : 第二次查询SQL语句的坐标column: 传递的列名--><collection property="studentList"ofType="com.cskaoyan.bean.one2more.Student"select="com.cskaoyan.mapper.ClazzMapper.queryStudentByClazzId"column="id"/></resultMap><!-- 第二次查询 --><select id="queryStudentByClazzId" resultType="com.cskaoyan.bean.one2more.Student">select id,name,age,gender,clazz_id as clazzId from student where clazz_id = #{id}</select><!-- 一对多的分次查询 查询入口--><select id="queryClazzWithStudentListByIdUseTimes" resultMap="clazzTimesMap">select id,name from clazz where id = #{id}</select>
<resultMap id="orderMap" type="com.wei.order.model.vo.ShowOrderVo"><id column="id" property="id"/><result column="userId" property="userId"/><result column="goodsDetailId" property="goodsDetailId"/><result column="goods" property="goods"/><result column="specId" property="spec"/><result column="goodsNum" property="goodsNum"/><result column="amount" property="amount"/><result column="stateId" property="stateId"/><result column="stateId" property="state"/><association property="user" javaType="com.wei.order.model.vo.UserVo"><result column="nickname" property="nickname"/><result column="name" property="name"/><result column="address" property="address"/><result column="phone" property="phone"/></association><association property="state"javaType="java.lang.String"column="stateId"select="com.wei.order.dao.OrderDao.selectStateById"/><association property="spec"javaType="java.lang.String"column="specId"select="com.wei.order.dao.OrderDao.selectSpecById"/></resultMap><!--第二次查询,根据stateId查状态--><select id="selectStateById" resultType="java.lang.String">select state from `condition`<where><if test="state!=-1">id=#{stateId}</if></where></select><!--第三次查询,根据型号id查型号--><select id="selectSpecById" resultType="java.lang.String">SELECT specName as specFROM `spec`WHERE id = #{specId}</select><!--第一次查询--><select id="selectAllOrderByBo" resultMap="orderMap">select id,userId,goodsId as goodsDetailId,goods,specId,goodsNum,amount,stateId,nickname,address,receiver as `name`,phonefrom `order2`<where><if test="bo.id != null and bo.id != ''">id = #{bo.id}</if><if test="bo.name != null and bo.name != ''">and nickname like concat("%", #{bo.name}, "%")</if><if test="bo.address != null and bo.address != ''">and address like concat("%", #{bo.address}, "%")</if><if test="bo.goods != null and bo.goods != ''">and goods like concat("%", #{bo.goods}, "%")</if><if test="bo.moneyLimit1 != null and bo.moneyLimit1 != ''">and amount <= #{bo.moneyLimit1}</if><if test="bo.moneyLimit1 != null and bo.moneyLimit1 != ''">and amount >= #{bo.moneyLimit1}</if><if test="bo.state !=-1">and stateId = #{bo.state}</if></where>limit #{bo.pagesize} offset ${(bo.currentPage - 1) * bo.pagesize}</select>
字符串拼接
<select id="selectGoodsByName" resultType="com.wei.mall.model.vo.GoodsSearchVo">select img,price,`name`,typeId,idfrom `goods`where `name` like concat("%", #{keyword}, "%")</select>
foreach
<update id="updateOrderByList" parameterType="list"><foreach collection="cartList" item="item">update `order2` setstateId = 1,goodsNum = #{item.goodsNum},amount = #{item.amount}whereid = #{item.id};</foreach></update>
