报错详情:
org.springframework.jdbc.BadSqlGrammarException:
### Error querying database. Cause: java.sql.SQLSyntaxErrorException: Unknown column 'yyy' in 'where clause'
### The error may exist in file [D:\xxxxx\xxxxxxx\xxxxxx\e20200-xxxx01-dal\target\classes\mapper\UserMapper.xml]
原因分析:
前端传过来的列名不明。
本来mybatis是通过${rolename}传递列名,写法如下:
UserMapper.xml
<if test="rolename != null and rolename != ''">
and USERID in (select m.user_id from user m where m.role_id in (${rolename}))
</if>
解决办法:
在${rolename}包一层单引号 ''
<if test="rolename != null and rolename != ''">
and USERID in (select m.user_id from user m where m.role_id in ('${rolename}'))
</if>