
正文
Mybatis02
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
1.mybatis动态sql
foreach
添加接口方法
编写BookVo类
BookMapper.xml
测试
结果
2.模糊查询
3.查询返回结果集
resultMap:适合使用返回值是自定义实体类的情况
resultType:适合使用返回值的数据类型是非自定义的,即jdk的提供的类型
3.1 使用resultMap返回自定义类型集合
3.2 使用resultType返回List<T>
3.3 使用resultType返回单个对象
3.4 使用resultType返回List<Map>,适用于多表查询返回结果集
3.5 使用resultType返回Map<String,Object>,适用于多表查询返回单个结果集
<select id="querySingleBook" resultType="com.hmc.model.Book" parameterType="com.hmc.model.Book"> SELECT
<include refid="Base_Column_List"/>
FROM t_book where id=#{id}
</select> <select id="queryBookResultMap" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM t_book
</select> <select id="queryBookBYListMap" resultType="map">
SELECT
<include refid="Base_Column_List"/>
FROM t_book
</select>
<select id="querySingleBookByMap" resultType="map" parameterType="com.hmc.model.Book"> SELECT
<include refid="Base_Column_List"/>
FROM t_book where id=#{id}
</select>
4.分页查询
为什么要重写mybatis的分页?
Mybatis的分页功能很弱,它是基于内存的分页(查出所有记录再按偏移量offset和边界limit取结果),在大数据量的情况下这样的分页基本上是没有用的
导入分页插件
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.2</version>
</dependency>
将pagehelper插件配置到mybatis中
<!-- 配置分页插件PageHelper, 4.0.0以后的版本支持自动识别使用的数据库 -->
<plugin interceptor="com.github.pagehelper.PageInterceptor">
</plugin>
5.特殊字符处理
>(>)
<(<)
&(&)
空格( )







