Mybatis常用配置

<mapper namespace="Message">
    <!--type:与数据库对应的模型类, id即为名字-->
    <resultMap type="main.entity.Message" id="MessageResult">
        <!--cloumn:数据库的列名 jdbcType:对应的类型,注意要用大写, property:模型类对应的属性名-->
        <!--主键是id 其他是result-->
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="command" jdbcType="VARCHAR" property="command"/>
        <result column="description" jdbcType="VARCHAR" property="description"/>
        <result column="content" jdbcType="VARCHAR" property="content"/>
    </resultMap>
    <!--将查出来的值放在resultMap所对应的column里面-->
    <!--parameterType传入查询的类参数类型-->

    <select id="queryMessageList" parameterType="main.entity.Message" resultMap="MessageResult">
        select id,command,description,content from message where 1=1
        <!--OGNL表达式   #{}在拼接mysql语句的时候, 会子自动转换为?, 并将command赋值-->
        <if test="command!=null and !&quot;&quot;.equals(command.trim())">and command=#{command}</if>
        <if test="description!=null and !&quot;&quot;.equals(description.trim())">and description = #{description}</if>
    </select>

    <!--删除语句-->
    <delete id="deleteOne" parameterType="String">
        delete from message where id=#{_parameter}
    </delete>

    <delete id="deleteBatch" parameterType="List" >
        delete from message where id in(
        <foreach collection="list" item="item" separator=",">
            #{item}
        </foreach>
        )
    </delete>
<!--select ID,COMMAND,DESCRIPTION,CONTENT from MESSAGE
        <where>
            <if test="command != null and !&quot;&quot;.equals(command.trim())">
                and COMMAND=#{command}
            </if>
            <if test="description != null and !&quot;&quot;.equals(description.trim())">
                and DESCRIPTION like '%' #{description} '%'
            </if>
        </where>-->
    <!--<delete id="deleteOne" parameterType="int">-->
  	<!--delete from MESSAGE where ID = #{_parameter}-->
  <!--</delete>-->

    <!--<delete id="deleteBatch" parameterType="java.util.List">-->
        <!--delete from MESSAGE where ID in(-->
        <!--<foreach collection="list" item="item" separator=",">-->
            <!--#{item}-->
        <!--</foreach>-->
        <!--)-->
    <!--</delete>-->
</mapper>
<!--最后还需要将mapper在xml中配置-->

<mappers>
  <mapper resource="/main/config/sql/Message.xml"></mapper>

</mappers>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

江湖无为

感谢你们的鼓励

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值