1. 程式人生 > >mybatis #{}無法自動新增引號的錯誤

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>