日期:2014-05-17  浏览次数:20877 次

ibatis的产map类型做参数的时候,总是说属性找不到,怎么回事?
service里这样:
Java code
paramMap.put("groupId", groupId);
        paramMap.put("fromIndex", page.getFromIndex());
        paramMap.put("pageSize",page.getPageSize());


根据用户组查询该组下的所以用户。
xml这么写的:
XML code
<!-- 根据用户组id查询该组下的所有用户 -->
    <select id="selectUserByGroupId" parameterClass="java.util.Map" resultMap="resultUsers">
        SELECT
            a.USER_ID,
            a.LOGIN_NAME,
            a.SHOW_NAME,
            a.PASS_WORD,
            a.CREATE_TIME,
            a.GROUP_ID,
            a.ADMIN_FLG,
            b.ID,
            b.GROUP_NAME,
            b.DISPLAY_ORDER,
            b.HIDE_FLG
        FROM
            table_user AS a
        LEFT JOIN 
            table_group AS b 
        ON 
            b.ID = a.GROUP_ID
        WHERE
            a.GROUP_ID = #groupId#
        ORDER BY
            a.USER_ID DESC
        <dynamic>
            <isNotNull property="fromIndex">
            <isNotNull property="pageSize">
                LIMIT #fromIndex# , #pageSize#
            </isNotNull>
            </isNotNull>
        </dynamic>
    </select>


报错如下:
Java code
org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0];   
--- The error occurred while applying a parameter map.  
--- Check the Users.selectUserByGroupId-InlineParameterMap.  
--- Check the parameter mapping for the 'groupId' property.  
--- Cause: java.lang.NullPointerException; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred while applying a parameter map.  
--- Check the Users.selectUserByGroupId-InlineParameterMap.  
--- Check the parameter mapping for the 'groupId' property.  
--- Cause: java.lang.NullPointerException
    org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:124)


有一行:Check the parameter mapping for the 'groupId' property. [size=16px][/size]

------解决方案--------------------
检查 paramMap.put("groupId", groupId);
groupId是不是空的
SQLMAQP 凡是有参数的地方都加上<isNotNull property="groupId">判断

a.GROUP_ID = #groupId#
这里你也要加上判断 当这个参数为空的时候 这条SQL 不要加进去
------解决方案--------------------
看是你有空值传过去了!或者没有传值!
我项目中用的代码 希望对你有帮助 ,调用存储过程的代码 
xml中
<parameterMap class="java.util.Map" id="swapParameters2">
<parameter property="contractId" javaType="java.lang.String" jdbcType="VARCHAR" mode="IN" />
<parameter property="startDate" javaType="java.lang.String" jdbcType="VARCHAR" mode="IN"/>
<parameter property="endDate" ja