[MyBatis日记]问题汇总
2016-02-21 23:25
309 查看
问题一:mybatis映射文件insert不执行,而直接用sql则可以插入成功
解决方案:
studentMapper.insertStudent(student);在执行晚SQL语句之后,记得session.commit(); |
问题二:中文显示乱码问题
解决方案:
配置数据库地址时加上编码格式characterEncoding:<propertyname="url"value="jdbc:mysql://localhost:3306/test?characterEncoding=utf8"/> |
问题三:XML文件中大于号小于号问题
解决方案一:用了转义字符把>和<替换掉
[code]<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEmapperPUBLIC"-//mybatis.org//DTDMapper3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mappernamespace="com.sjf.mapper.CourseMapper">
<resultMapid="CourseResultMap"type="com.sjf.bean.Course">
<idproperty="ID"column="ID"/>
<resultproperty="name"column="name"/>
<resultproperty="desc"column="description"/>
<resultproperty="startDate"column="startDate"/>
<resultproperty="endDate"column="endDate"/>
</resultMap>
<selectid="getCourseByCondation"parameterType="hashmap"resultMap="CourseResultMap">
SELECT*FROMCourse
WHEREteacherID=#{teacherID}
<iftest="courseName!=null">
ANDNAME=#{courseName}
</if>
<iftest="startDate!=null">
ANDstartDate>=#{startDate}
</if>
<iftest="endDate!=null">
ANDendDate<=#{endDate}
</if>
</select>
</mapper>
转义字符表:
转义符 | 符号 |
---|---|
< | <(小于号) |
> | >(大于号) |
& | &(和) |
' | '(单引号) |
" | "(双引号) |
因为这个是xml格式的,所以不允许出现类似“>”这样的字符,但是都可以使用<![CDATA[]]>符号进行说明,将此类符号不进行解析。
[code]<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEmapperPUBLIC"-//mybatis.org//DTDMapper3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mappernamespace="com.sjf.mapper.CourseMapper">
<resultMapid="CourseResultMap"type="com.sjf.bean.Course">
<idproperty="ID"column="ID"/>
<resultproperty="name"column="name"/>
<resultproperty="desc"column="description"/>
<resultproperty="startDate"column="startDate"/>
<resultproperty="endDate"column="endDate"/>
</resultMap>
<selectid="getCourseByCondation"parameterType="hashmap"resultMap="CourseResultMap">
SELECT*FROMCourse
WHEREteacherID=#{teacherID}
<iftest="courseName!=null">
ANDNAME=#{courseName}
</if>
<iftest="startDate!=null">
<![CDATA[ANDstartDate>=#{startDate}]]>
</if>
<iftest="endDate!=null">
<![CDATA[ANDendDate<=#{endDate}]]>
</if>
</select>
</mapper>
相关文章推荐
- Swift基础语法&&入门教程_字符串,数组_字典
- git push warning: push.default is unset 分析解决
- Conversion to Dalvik format failed with error 1
- MySQL 主从复制与读写分离概念及架构分析
- nyoj 123 士兵杀敌四
- C语言运算符优先级详细列表
- 自定义浏览器弹窗
- [java]_[线程池的使用]
- 中值滤波 matlab实现
- C++面向对象编程<三>:操作符重载
- 身份证号码工具类
- MySQL 启动时禁用了 InnoDB 引擎的解决方法
- mvc框架嵌入文本编辑器
- 设计模式专题00——基础
- JavaScript 中的 .prototype
- Material Design风格的水波涟漪效果(Ripple Effect)的实现
- bozj2186 [Sdoi2008]沙拉公主的困惑
- javascript之一切皆为对象3
- 《Node.js+MongoDB+AngularJS Web开发》读书笔记及联想
- CodeForces 589F-Gourmet and Banquet-二分答案