1、在用动态SQL老一个There is no getter for property named 'id' in 'class java.lang.Integer错误
<select id="queryUser" parameterType="Integer" resultType="com.accp.TestMybatis.dto.User">
select * from scott.users
<if test="id!=null">
where id = #{id}
</if>
</select>
<!--但是把if去掉如:-->
<select id="queryUser" parameterType="Integer" resultType="com.accp.TestMybatis.dto.User">
select * from scott.users where id = #{id}
</select>
<!--又正常,非常蛋疼。-->
解决方法:
将<if test="id!=null">改为
<if test="_parameter!=null">
where id = #{_parameter}
</if>
问题来源:http://bbs.csdn.net/topics/370173955?page=1
2、在mybatis中使用select top #{top} * from tb 语句出现“@P0' 附近有语法错误"。
问题分析:
语句编译后#{}是预处理状态,在Java中对数据库查询时经常使用“Select Top ? * From 表名 Where 列名 =
?”的SQL语句,此时的问号是PreparedStatement预编译对象的参数占位符,需要使用setXX()系列方法对其赋值后再执行。但是,Top后面是不允许使用问号占位符的,此处的错误就是由此引起的。
解决方法:
语句修改为:select top ${top} * from tb
问题来源:http://ekekyn.blog.163.com/blog/static/313887320122159632536/
3、使用SQL批量添加数据时,出现The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Too many parameters were provided in this RPC request. The maximum is 2100.
SQL语句:
INSERT INTO [TABLE]([FIELD],[FIELD]...)VALUES([VALUE],[VALUE]...),([VALUE],[VALUE]...)...
解决方法:
public void batchInsert(List<Course> courses) {
for(int i = 0,s = 0; i < courses.size()/100;i++,s+=100){
sqlSessionTemplate.insert("com.netDragon.domain.Course.batchInsert", courses.subList(s, s+100));
}
if(courses.size() - courses.size()/100*100 > 0)
sqlSessionTemplate.insert("com.netDragon.domain.Course.batchInsert", courses.subList(courses.size()/100*100,courses.size()));
}