MyBatis的知识点
来源:互联网 发布:js清除浏览器缓存数据 编辑:程序博客网 时间:2024/06/07 22:35
mybatis 分页技术
MyBatis 自带分页 是吧查询出来的结果集进行分页 ====内存分页
eg: RowBounds rb= new RowBounds(offset, limt); //offset 起始行 limt 一页多少个
2,Mybatis与Mysql结合 当表中有自动增长 插入后 查看ID
<insert id="insertUser" parameterType="com.shi.User">
<selectkey keyProperty="id" resultType="Integer" order="after">
select last_insert_id();
</selectkey>
insert into ...
</insert>
3,#{}代表占位符(防sql注入) ${}代表字符串连接(不防sql注入)
4,指定Mapper文件的方法
<mappers>
<!-- mapper 标签--->
<mapper resource="mapper.xml所在的位置"/>
<mapper class="mapper.xml对应接口所在的位置"/>
<!-- package 标签 要求 接口名与mapper 名一样 放在同一个包下-->
<package name="包名"/>
</mappers>
5,resultMap 映射
<!-- -->
<resultMap type="" id="" >
<id cloumn="" property="" 主键>
<result 普通属性>
<association 一对一>
<collection 一对多>
</resultMap>
6,if标签
<if test="布尔表达式"></if>
<where>
<if></if> //去掉第一个if的前and
</where>
7,sql片段
<sql id="">抽取公共sql语句</sql>
<select>
<include rfid="sql标签的id" /> //引入公共的sql
</select>
8,当传入的值是多个值时使用 <foreach></foreach> 标签
<foreach collection="要遍历的集合 数组放array 集合写list" item =“ 遍历的元素” separate=“,断点,分割点” open=“ id in (” close=“)” >
#{id}
</foreach>
9,在resultMap映射时 单张表查询可以只映射 字段和属性不同的 在一对一关联association 时必须映射所有的字段和属性
10,在resultMap 映射 collection时 <collection property="字段名" ofType=“集合的泛型名”
11,mapper动态代理增强版----扫描
普通mapper动态代理:
<bean name="dao" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="com.run.dao.UserMapper"></property>
<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
</bean>
mapper增强--扫描
<bean class=“org.mybatis.spring.mapper.MapperScannerCofigurer”>
<!-- 注入基本包-->
<property name="basePackage" value="mapper接口所在的包">
</bean>
MyBatis 自带分页 是吧查询出来的结果集进行分页 ====内存分页
eg: RowBounds rb= new RowBounds(offset, limt); //offset 起始行 limt 一页多少个
2,Mybatis与Mysql结合 当表中有自动增长 插入后 查看ID
<insert id="insertUser" parameterType="com.shi.User">
<selectkey keyProperty="id" resultType="Integer" order="after">
select last_insert_id();
</selectkey>
insert into ...
</insert>
3,#{}代表占位符(防sql注入) ${}代表字符串连接(不防sql注入)
4,指定Mapper文件的方法
<mappers>
<!-- mapper 标签--->
<mapper resource="mapper.xml所在的位置"/>
<mapper class="mapper.xml对应接口所在的位置"/>
<!-- package 标签 要求 接口名与mapper 名一样 放在同一个包下-->
<package name="包名"/>
</mappers>
5,resultMap 映射
<!-- -->
<resultMap type="" id="" >
<id cloumn="" property="" 主键>
<result 普通属性>
<association 一对一>
<collection 一对多>
</resultMap>
6,if标签
<if test="布尔表达式"></if>
<where>
<if></if> //去掉第一个if的前and
</where>
7,sql片段
<sql id="">抽取公共sql语句</sql>
<select>
<include rfid="sql标签的id" /> //引入公共的sql
</select>
8,当传入的值是多个值时使用 <foreach></foreach> 标签
<foreach collection="要遍历的集合 数组放array 集合写list" item =“ 遍历的元素” separate=“,断点,分割点” open=“ id in (” close=“)” >
#{id}
</foreach>
9,在resultMap映射时 单张表查询可以只映射 字段和属性不同的 在一对一关联association 时必须映射所有的字段和属性
10,在resultMap 映射 collection时 <collection property="字段名" ofType=“集合的泛型名”
11,mapper动态代理增强版----扫描
普通mapper动态代理:
<bean name="dao" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="com.run.dao.UserMapper"></property>
<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
</bean>
mapper增强--扫描
<bean class=“org.mybatis.spring.mapper.MapperScannerCofigurer”>
<!-- 注入基本包-->
<property name="basePackage" value="mapper接口所在的包">
</bean>
阅读全文
0 0
- MyBatis的知识点
- 有关mybatis的一些知识点
- 关于MyBatis的一些知识点
- 关于mybatis的知识点整理
- mybatis相关知识点的总结
- MyBatis知识点
- mybatis知识点
- MyBatis知识点
- mybatis知识点
- Mybatis知识点
- MyBatis Generator的一些知识点释疑
- Mybatis中重要的小知识点
- mybatis中xml文件的相关知识点
- mybatis PageHelper和pageInfo的相关知识点
- mybatis知识点学习
- mybatis小知识点
- MyBatis知识点1
- mybatis知识点总结
- tomcat大量time wait问题
- Spring Data JPA入门
- #bzoj1846
- 破解防拷贝脚本
- C 预处理器和C库
- MyBatis的知识点
- linux查看日志
- 欢迎使用CSDN-markdown编辑器
- pycharm + virtualenv搭建python2.7 和python 3.0的多python运行环境
- 解决Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
- ZOJ-3329 One Person Game(期望dp)
- 深刻理解Python的元类
- Linux iptables防火墙实用模板
- 【MyBatis】MyBatis+SpringMVC+EasyUI整合分页