码迷,mamicode.com
首页 > 其他好文 > 详细

mybatis---知识点复习

时间:2016-11-23 23:47:06      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:用户   integer   rom   返回   lan   sso   知识   poj   str   

 mybatis的配置文件是configuation.xml是配置文件,主要是配置jdbc(用来创建sessionfactory)以及映射文件的别名,

 

一对多:

<mapper namespace="com.yiibai.userMaper">
	<!-- User 级联文章查询 方法配置 (一个用户对多个文章)  -->
	
	<resultMap type="User" id="resultUserMap">
		<result property="id" column="user_id" />
		<result property="username" column="username" />
		<result property="mobile" column="mobile" />
		<collection property="posts" ofType="com.yiibai.pojo.Post" column="userid">
			<id property="id" column="post_id" javaType="int" jdbcType="INTEGER"/>    
            <result property="title" column="title" javaType="string" jdbcType="VARCHAR"/>
            <result property="content" column="content" javaType="string" jdbcType="VARCHAR"/> 
		</collection>
	</resultMap>

	<select id="getUser" resultMap="resultUserMap" parameterType="int">
		SELECT u.*,p.*
		FROM user u, post p
		WHERE u.id=p.userid AND id=#{user_id} 
  </select>

</mapper>

#########################
<collection property="posts" ofType="com.yiibai.pojo.Post" column="userid">
			<id property="id" column="post_id" javaType="int" jdbcType="INTEGER"/>    
            <result property="title" column="title" javaType="string" jdbcType="VARCHAR"/>
            <result property="content" column="content" javaType="string" jdbcType="VARCHAR"/> 
		</collection>

collection对多,column = userid 是对于 posts表来说的关联user的字段名称


###################################

多对一

	<resultMap type="Post" id="resultPostsMap">
		<result property="id" column="post_id" />
		<result property="title" column="title" />
		<result property="content" column="content" />
	      <association property="user" javaType="User">  
	        <id property="id" column="userid"/>   
	        <result property="username" column="username"/>   
	        <result property="mobile" column="mobile"/>   
               </association> 
	</resultMap>


MyBatis使用RowBounds实现的分页是逻辑分页,也就是先把数据记录全部查询出来,然在再根据 offset 和 limit 截断记录返回。





mybatis---知识点复习

标签:用户   integer   rom   返回   lan   sso   知识   poj   str   

原文地址:http://www.cnblogs.com/tcdxx/p/6095482.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!