学习mybatis注意的重要问题

最近在使用mybatis,遇到了一些问题,个人觉得有必要记录并分享给大家。

1.在sql语句中遇到sql中的关键字,必须用键盘上Tab键上一个按键引用起来,如:key在mysql中是一个关键字

     <![CDATA[
            select
                seq_id,
                user_name,
                `key`
            from test
        ]]>


2.根据经验,尽量在resultType=" "中使用Bean作为参数,不建议使用map做参数。


我的第一个mybatis文件:一个简单的查询,`(*∩_∩*)′

<?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.eostek.dao.IQueryDao">

    <resultMap id="unionMap" type="unionBean">
        <result column="seq_id" property="id" />
        <result column="user_name" property="name" />
        <result column="key" property="key" />
    </resultMap>

    <select id="query" resultMap="unionMap">
        <![CDATA[
            select
                seq_id,
                user_name,
                `key`
            from test
        ]]>
    </select>

    <select id="queryByName" parameterType="java.lang.String" resultMap="unionMap">
        <![CDATA[
            select
                seq_id,
                user_name,
                `key`
            from test
        ]]>
        <where>
            <![CDATA[
                user_name like concat('%',#{name},'%')
            ]]>
        </where>
    </select>
    
    <!-- <select id="query" resultType="unionBean">
        <![CDATA[
            select
                seq_id id,
                user_name name
            from test
        ]]>
    </select> -->

</mapper>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值