在学习mybatis,曾报错:
org.apache.ibatis.exceptions.PersistenceException
Error building SqlSession.
### The error may exist in mappers/StudentMapper.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'mappers/StudentMapper.xml'. Cause: org.apache.ibatis.builder.BuilderException: Parsing error was found in mapping #{}. Check syntax #{property|(expression), var1=value1, var2=value2, ...}
在一点点查询代码语法是否出错无解后,无疑中看到一篇文章评论中写道,于是就把问题解决了
原映射文件代码为
-- id里面为DAO中的方法名 -- #{}中间的为Student类中的参数,因为insertStudent传参有Student类所以直接可以写Student中的属性 insert into tb_students(stu_num,stu_name,stu_gender,stu_age) values(#{stuNum},#{stuName},#{stuGender},#{stuAge})
把注释从 -- 修改为 ,就可以了
现代码为:
insert into tb_students(stu_num,stu_name,stu_gender,stu_age) values(#{stuNum},#{stuName},#{stuGender},#{stuAge})
另外我还有了个发现,在映射文件中使用 -- 或者 xml是不会解析为注释的,只有
是不会被解析里面的内容的



