<!-- 使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>
<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>