mybatis中xml配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lu1171901273/article/details/82763104

<if test="list != null">
    AND column in 
    //column(数据库中的列) collection中的list是mapper接口传递过来的字段(这里是list类型的)
    //如果list是list<String>,item是list中的每一项, 
    //如果list是list<Map<String,String>> item是list中的每一个map
    //加上jdbcType=VARCHAR,就算是空也不会报错 null也可以传递
    //index指定一个名字,用于表示在迭代过程中,每次迭代到的位置,
    //separator表示在每次进行迭代之间以什么符号作为分隔符,
    //open表示该语句以什么开始,
    //close表示以什么结束,
    <foreach item="item" index="index" collection="list" open="(" separator="," close=")">  
            #{item,jdbcType=VARCHAR}   //#{item.key}
    </foreach>  
</if>

parameterMap(传入参数封装为javaBean,对应配置文件中javaBean的Id),
resultMap(输出参数封装为javaBean,对应配置文件中javaBean的Id),
parameterType(传入参数,可以是String,也可以是Map,Map中可以封装List、Array)
resultType(输出参数,可以是Map(当是select *时也可以是Map,但是在Mapper接口中需要用List接收))
<select id="" parameterMap="" parameterType="" resultType="" resultMap="" ></select>

这里是可以直接写sql
 <![CDATA[ status != #{status} ]]>
 <sql id="">
    <if test="id != null">
        and id = #{id}
    </if>
</sql>

//用于拼接字符串 
CONCAT('%', CONCAT(#{con}, '%'))

猜你喜欢

转载自blog.csdn.net/lu1171901273/article/details/82763104