<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.sun.dao.UserDao"> <!--封装sql条件,封装可以重用--> <sql id="user_Where"> <where> <if test="iSecondhandID !=null"> and iSecondhandID=#{iSecondhandID} </if> <if test="iStatus !=null"> and iStatus=#{iStatus} </if> </where> </sql> <!-- 查询单条记录 --> <select id="selectUserById" parameterType="int" resultType="com.sun.dto.User"> SELECT * FROM t_secondhand_pic WHERE iAutoID = #{value} </select> <!--插入单条记录--> <insert id="insert" parameterType="int"> INSERT INTO t_secondhand_pic(iStatus,sImgKey,sExt,iImgType) VALUES(#{value},'19dc9080f7abc866ea7ab857d9cd03c7032e7a96','jpg','2'); </insert> <!--查询多条语句--> <select id="selectByUser" parameterType="com.sun.dto.UserVO" resultType="com.sun.dto.User"> select * from t_secondhand_pic where iSecondhandID=#{user.iSecondhandID} and iStatus=#{user.iStatus} </select> <!--查询统计个数--> <!--UserDao public List<User> selectByUser(UserVO userVO);--> <select id="selectCount" parameterType="com.sun.dto.UserVO" resultType="int"> select count(*) from t_secondhand_pic where iSecondhandID=#{user.iSecondhandID} and iStatus=#{user.iStatus} </select> <!--查询多个where语句--> <select id="selectWhere" parameterType="com.sun.dto.User" resultType="com.sun.dto.User"> select * from t_secondhand_pic <!--调用sql条件--> <include refid="user_Where"/> </select> <!--查询 in 语句--> <!-- <select id="selectIn" parameterType="com.sun.dto.User" resultType="com.sun.dto.User"> select * from t_secondhand_pic <where> <if test="ids !=null" > <!– foreach:循环传入的集合参数 collection:出入集合的变量名称 item:每次循环将循环出的数据传入到这个变量中 open:循环开始拼接的字符串 close:循环结束拼接的字符串 separator:循环中的分隔符 –> <foreach collection="ids" item="id" open="id in (" close=")" separator=","> #{id} </foreach> </if> </where> </select>--> <!--一对一自动映射--> <!-- <select id="selectOneToOne" resultType="CustomOrder"> select </select>--> <!--一对一手动映射--> <!--多对多映射--> </mapper>