• MyBaits 常见面试题


    1 在mapper中如何传递多个参数?

    第1种:

    //DAO层的函数
    
    Public UserselectUser(String name,String area);  
    //对应的xml,#{0}代表接收的是dao层中的第一个参数,#{1}代表dao层中第二参数,更多参数一致往后加即可。
    
    <select id="selectUser"resultMap="BaseResultMap">  
        select *  fromuser_user_t   whereuser_name = #{0} anduser_area=#{1}  
    </select>  

    第2种: 使用 @param 注解:

        import org.apache.ibatis.annotations.param; 
            public interface usermapper { 
             user selectuser(@param(“username”) string username, 
             @param(“hashedpassword”) string hashedpassword); 
            }
    然后,就可以在xml像下面这样使用(推荐封装为一个map,作为单个参数传递给mapper): 
        <select id=”selectuser” resulttype=”user”> 
             select id, username, hashedpassword 
             from some_table 
             where username = #{username} 
             and hashedpassword = #{hashedpassword} 
        </select>

    第2种: 使用map:

    <select id="getSysInfo" parameterType="java.util.Map" resultType="SysWeb">
      select t.sysSiteId, t.siteName, t1.mzNum as siteTagNum, t1.mzName as siteTag, t.url, t.iconPath
       from TD_WEB_SYSSITE t
       left join TD_MZ_MZDY t1 on t1.mzNum = t.siteTag and t1.mzType = 10
       WHERE t.siteTag = #{siteTag } 
       and t.sysSiteId not in 
       <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
           #{item}
       </foreach>
     </select>

     2 mybaits in查询

      

     
  • 相关阅读:
    C#常用错误
    服务器应用程序不可用
    iis设置asp站点
    观看列表
    make otapackage出错
    ubuntu network is unreachable解决办法
    ubuntu10.04主题
    ubuntu10.04 adb和jdk环境变量设置
    ubuntu-硬盘分区、格式化、自动挂载配置
    apk安装过程
  • 原文地址:https://www.cnblogs.com/shujiying/p/10232979.html
Copyright © 2020-2023  润新知