mybatis #{}无法自动添加引号的错误

传入string类型时,无法自动添加引号,导致SQL将值识别为列名,导致SQL失败

 

解决:使用map类型代替string的传值

Map<String, String> map = new HashMap<>(2);
map.put("userName", userName);
return userMapper.selectUserByName(map);

 

<select id="selectUserByName" parameterType="map" resultType="userDO">
    select
        user_id as userId,
        user_name as userName,
        user_password as userPassword,
        user_level as userLevel,
        user_gmt_create as userGmtCreate,
        user_gmt_modified as userGmtModified
    from user
    where user_name = #{userName}
</select>
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务