在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/Java/ mybatis的mapper,參數(shù)為map的話,為啥報(bào)這個(gè)錯(cuò)?

mybatis的mapper,參數(shù)為map的話,為啥報(bào)這個(gè)錯(cuò)?

java.lang.IllegalArgumentException: Name for argument type [int] not available, and parameter name information not found in class file either.
 <select id="get_cases" resultType="News" parameterType="java.util.Map">
        SELECT * FROM `case` WHERE state=0 and `type`= #{type,jdbcType=INTEGER}
        order by create_time desc limit ${num,jdbcType=INTEGER}
        
    </select>

圖片描述

回答
編輯回答
無(wú)標(biāo)題

XML那里寫(xiě)錯(cuò)了,更正成parameterType="map",并不是java.util.Map

擴(kuò)展閱讀:

在mapper中如何傳遞多個(gè)參數(shù)?

第一種:使用占位符的思想

  • 在映射文件中使用#{0},#{1}代表傳遞進(jìn)來(lái)的第幾個(gè)參數(shù)
  • 使用@param注解:來(lái)命名參數(shù)

#{0},#{1}方式


//對(duì)應(yīng)的xml,#{0}代表接收的是dao層中的第一個(gè)參數(shù),#{1}代表dao層中第二參數(shù),更多參數(shù)一致往后加即可。

<select id="selectUser"resultMap="BaseResultMap">  
    select *  fromuser_user_t   whereuser_name = #{0} anduser_area=#{1}  
</select>  

@param注解方式


        public interface usermapper { 
         user selectuser(@param(“username”) string username, 
         @param(“hashedpassword”) string hashedpassword); 
        }
 <select id=”selectuser” resulttype=”user”> 
         select id, username, hashedpassword 
         from some_table 
         where username = #{username} 
         and hashedpassword = #{hashedpassword} 
    </select>

第二種:使用Map集合作為參數(shù)來(lái)裝載


     try{
            //映射文件的命名空間.SQL片段的ID,就可以調(diào)用對(duì)應(yīng)的映射文件中的SQL


            /**
             * 由于我們的參數(shù)超過(guò)了兩個(gè),而方法中只有一個(gè)Object參數(shù)收集
             * 因此我們使用Map集合來(lái)裝載我們的參數(shù)
             */
            Map<String, Object> map = new HashMap();
            map.put("start", start);
            map.put("end", end);
            return sqlSession.selectList("StudentID.pagination", map);
        }catch(Exception e){
            e.printStackTrace();
            sqlSession.rollback();
            throw e;
        }finally{
            MybatisUtil.closeSqlSession();
        }

    <!--分頁(yè)查詢-->
    <select id="pagination" parameterType="map" resultMap="studentMap">

        /*根據(jù)key自動(dòng)找到對(duì)應(yīng)Map集合的value*/
        select * from students limit #{start},#{end};

    </select>
2017年10月24日 01:39
編輯回答
慢半拍

既然是map,那么入?yún)?yīng)該是一個(gè)對(duì)象,type是map中的一個(gè)屬性的話,這個(gè)位置應(yīng)該是

 <select id="get_cases" resultType="News" parameterType="java.util.Map">
        SELECT * FROM `case` WHERE state=0 and `type`= #{map.type,jdbcType=INTEGER}
        order by create_time desc limit ${map.num,jdbcType=INTEGER}
 </select>

另外,建議使用@Param注解將參數(shù)命名。

2017年6月6日 00:31