错误:
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.sql.SQLDataException: Cannot determine value type from string 'id'
### The error may exist in mybatis/user.xml
### The error may involve user.getUserById-Inline
### The error occurred while setting parameters
### SQL: SELECT 'id', 'username', 'birthday', 'sex', 'address' FROM user WHERE id=?
### Cause: java.sql.SQLDataException: Cannot determine value type from string 'id'
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:111)
错误原因:查询不当
<select id="getUserById" parameterType="int" resultType="com.mybatis.pojo.User">
SELECT 'id',
'username',
'birthday',
'sex',
'address'
FROM user WHERE id=#{id1}
</select>
应改为:
<select id="getUserById" parameterType="int" resultType="com.mybatis.pojo.User">
SELECT * FROM user WHERE id=#{id1}
</select>
本文解析了一起MyBatis在执行SQL查询时遇到的PersistenceException异常,详细分析了错误原因在于XML配置文件中SQL语句的不当使用,并提供了正确的SQL语句修改方案。
1406

被折叠的 条评论
为什么被折叠?



