条件查询用户接口报错
来源:1-1 导学

phoenix_wsf
2024-05-25
条件查询用户接口报错,这个平台代码提交不上去
Preparing: SELECT DISTINCT u.id, u.name, u.sex, u.tel, u.email, d.dept_name AS dept, u.hiredate, u.root, u.status, ( SELECT GROUP_CONCAT( role_name separator "," ) FROM tb_role WHERE JSON_CONTAINS ( u.role, CONVERT (id, CHAR) ) ) AS roles FROM tb_user u JOIN tb_role r ON JSON_CONTAINS ( u.role, CONVERT (r.id, CHAR) ) LEFT JOIN tb_dept d ON u.dept_id = d.id WHERE u.sex=? ORDER BY u.id ASC LIMIT 0, 10
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6dc66add]
2024/05/25 13:10:59 ERROR 执行异常
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='sex', mode=IN, javaType=class java.lang.Object, 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: 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='sex', mode=IN, javaType=class java.lang.Object, 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: 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).
userDAO.xml
<select id="searchByPage" parameterType="map" resultType="hashmap">
/*!mycat: sql=
SELECT DISTINCT u.id,
u.name,
u.sex,
u.tel,
u.email,
d.dept_name AS dept,
u.hiredate,
u.root,
u.status,
(
SELECT GROUP_CONCAT( role_name separator "," )
FROM tb_role
WHERE JSON_CONTAINS ( u.role, CONVERT (id, CHAR) )
) AS roles
FROM tb_user u
JOIN tb_role r ON JSON_CONTAINS ( u.role, CONVERT (r.id, CHAR) )
LEFT JOIN tb_dept d ON u.dept_id = d.id
<where>
<if test="name!=null">
AND u.name LIKE "%${name}%"
</if>
<if test="sex!=null">
AND u.sex=#{sex}
</if>
<if test="role!=null">
AND r.role_name=#{role}
</if>
<if test="deptId!=null">
AND d.id=#{deptId}
</if>
<if test="status!=null">
AND u.status=#{status}
</if>
</where>
ORDER BY u.id ASC
LIMIT ${start},${length}
*/
SELECT DISTINCT u.id,
u.name,
u.sex,
u.tel,
u.email,
d.dept_name AS dept,
u.hiredate,
u.root,
u.status,
(
SELECT GROUP_CONCAT( role_name separator "," )
FROM tb_role
WHERE JSON_CONTAINS ( u.role, CONVERT (id, CHAR) )
) AS roles
FROM tb_user u
JOIN tb_role r ON JSON_CONTAINS ( u.role, CONVERT (r.id, CHAR) )
LEFT JOIN tb_dept d ON u.dept_id = d.id
<where>
<if test="name!=null">
AND u.name LIKE "%${name}%"
</if>
<if test="sex!=null">
AND u.sex=#{sex}
</if>
<if test="role!=null">
AND r.role_name=#{role}
</if>
<if test="deptId!=null">
AND d.id=#{deptId}
</if>
<if test="status!=null">
AND u.status=#{status}
</if>
</where>
ORDER BY u.id ASC
LIMIT ${start}, ${length}
</select>
还有就是我是用
LIMIT ${start}, ${length} 可以查询,但是使用LIMIT #{start}, #{length}也是同样报mybatis参数错误
写回答
1回答
-
神思者
2024-05-25
这个SQL语句要放在MyCat上面执行,你是把SQL交给MySQL执行了吧
012024-05-25
相似问题