赞
踩
<!--定义一个查询方法,用于获取日志列表-->
<!--方法ID为getLogList,返回类型com.main.server.api.model.SysLogModel,参数类型为com.main.server.api.dto.LogDto-->
<select id="getLogList" resultType="com.main.server.api.model.SysLogModel" parameterType="com.main.server.api.dto.LogDto">
/*查询语句,通过join操作查询sys_log和sys_user表的数据*/
/*根据log_user_id和id关联sys_log和sys_user表,获取用户名*/
select a.*,b.real_name as user_name from sys_log a join sys_user b on a.log_user_id = b.id
/*使用where子句过滤查询条件*/
<where>
/*如果LogDto中的userId不为空,则添加过滤条件b.id = #{userId}*/
<if test="userId != null">
b.id = #{userId}
</if>
/*如果LogDto中的logMsg不为空,则添加过滤条件log_msg like concat('%',#{logMsg},'%')*/
/*使用concat函数和like操作符实现模糊查询*/
<if test="logMsg != null and logMsg.trim() != ''">
and log_msg like concat('%',#{logMsg},'%')
</if>
</where>
/*按照id降序排序排列查询结果*/
order by id desc
</select>
java.lang.RuntimeException: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='userId', mode=IN, javaType=class java.lang.Integer, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='userId', mode=IN, javaType=class java.lang.Integer, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
Caused by: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='userId', mode=IN, javaType=class java.lang.Integer, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:89)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:93)
Caused by: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:55)
at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:87)
... 59 more
Caused by: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
把注释去掉
<!--定义一个查询方法,用于获取日志列表-->
<!--方法ID为getLogList,返回类型com.main.server.api.model.SysLogModel,参数类型为com.main.server.api.dto.LogDto-->
<select id="getLogList" resultType="com.main.server.api.model.SysLogModel" parameterType="com.main.server.api.dto.LogDto">
/*查询语句,通过join操作查询sys_log和sys_user表的数据*/
/*根据log_user_id和id关联sys_log和sys_user表,获取用户名*/
select a.*,b.real_name as user_name from sys_log a join sys_user b on a.log_user_id = b.id
/*使用where子句过滤查询条件*/
<where>
<if test="userId != null">
b.id = #{userId}
</if>
<if test="logMsg != null and logMsg.trim() != ''">
and log_msg like concat('%',#{logMsg},'%')
</if>
</where>
/*按照id降序排序排列查询结果*/
order by id desc
</select>
想加注释也可以,可以用下面这种方式:
<!--定义一个查询方法,用于获取日志列表-->
<!--方法ID为getLogList,返回类型com.main.server.api.model.SysLogModel,参数类型为com.main.server.api.dto.LogDto-->
<select id="getLogList" resultType="com.main.server.api.model.SysLogModel" parameterType="com.main.server.api.dto.LogDto">
/*查询语句,通过join操作查询sys_log和sys_user表的数据*/
/*根据log_user_id和id关联sys_log和sys_user表,获取用户名*/
select a.*,b.real_name as user_name from sys_log a join sys_user b on a.log_user_id = b.id
/*使用where子句过滤查询条件*/
<where>
<!--如果LogDto中的userId不为空,则添加过滤条件b.id = #{userId}-->
<if test="userId != null">
b.id = #{userId}
</if>
<!--如果LogDto中的logMsg不为空,则添加过滤条件log_msg like concat('%',#{logMsg},'%')-->
<!--使用concat函数和like操作符实现模糊查询-->
<if test="logMsg != null and logMsg.trim() != ''">
and log_msg like concat('%',#{logMsg},'%')
</if>
</where>
/*按照id降序排序排列查询结果*/
order by id desc
</select>
在xml中,注释尽量用下面这种的
<!-- -->
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。