sring mybatis 注解应用

 <!-- 使Spring关注Annotation -->  
   <context:annotation-config />   
    <!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 -->
   <context:component-scan base-package="com.kocla.*" /> 

当然你也 可以用 AOP 来自己写,需要用到 threadlocal 对象传递一些信息哦


https://kenai.com/projects/shirospring/sources
https://kenai.com/projects/shirospring/sources/subversion/show


com.mchange.v2.c3p0.Aes;
Aes.decrypt(password);


association :一对一的关系建立,一个对象中有另一个对象属性;
public class MybatisOrder {      ....  
    private Mybatiscustomer customer;  


}


1:type="Blog"    可以理解为映射ORM类的别名
2:association property="author" 中的property 为Blog类中有一个 Author  author属性;
3:association property="author" column="blog_author_id"   中的column为 Author类中的主键别名 ,一般命名为取前面type类型名+"_"+主键名
4:association property="author" column="blog_author_id" javaType="Author"   中的javaType为组合关系中的实体类别名




<resultMap id="blogResult" type="Blog">  
<id property=”blog_id” column="id" />  
<result property="title" column="blog_title"/>  
<association property="author" column="blog_author_id" javaType="Author"  
resultMap=”authorResult”/>  
</resultMap>  
   
<resultMap id="authorResult" type="Author">  
<id property="id" column="author_id"/>  
<result property="username" column="author_username"/>  
<result property="password" column="author_password"/>  
<result property="email" column="author_email"/>  
<result property="bio" column="author_bio"/>  
</resultMap> <wbr>  




collection :一对多的关系建立,理解为一个对象中有一个list集合属性;
public class MybatisOrder {  
    private List<MybatisOrderItem> itemList;  
}




<resultMap id=”blogResult” type=”Blog”> 
<collection property="posts"  javaType=”ArrayList” column="blog_id" ofType="domain.blog.Post" select=”selectPostsForBlog”/> 
</resultMap>
<select id=”selectPostsForBlog” parameterType=”int” resultType="Author">
 SELECT * FROM POST WHERE BLOG_ID = #{id} 
</select>






http://jingyan.baidu.com/article/11c17a2c7f376af446e39d21.html


<!-- 批量插入,手动插入主键 -->    
<insert id="batchInsert" parameterType="list">   
INSERT INTO T_YGY_DEMO_TEACHER(ID , NAME)  
<foreach collection="list" item="teacher" separator="union all">
SELECT #{teacher.id} , #{teacher.name} FROM DUAL 
</foreach> 
</insert> 


<!-- 批量删除 -->    
<delete id="batchDelete" parameterType="list">   
DELETE FROM T_YGY_DEMO_TEACHER WHERE ID IN   
<foreach collection="list" item="teacher" open="(" separator="," close=")">#{teacher.id}
</foreach>   
</delete>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

tony168hongweigan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值