传入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>