论坛首页 Java企业应用论坛

ibatis3 beta 1 发布,新功能介绍

浏览 20879 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (1)
作者 正文
   发表时间:2009-08-13  
nathanlee 写道
bigfirebird 写道
就是。动态sql 增强了不少。jstl的标签加了好几个,开发越来越灵活了。

还有一个特别喜欢的就是insert之后貌似可以直接返回主键了。

貌似以前就有

我接到的主键都是null的,后来自己实现了一个读取主键的方法,能告诉下为啥不能返回主键吗?

ibatis有jstl标签吗?我怎么没见过
0 请登录后投票
   发表时间:2009-08-13  
blackwolf1983 写道
我希望赶快有中文版指南,英文看着太痛苦了。
变化也太大了,不能兼容以前的了


ibatis 3是一个全新的版本,几乎是重写,很多地方都精心的设计过,为什么要兼容以前的版本呢,那样只会背上沉重的包袱,就像jdk一样,如果java能像python那样,放下一些包袱,放弃一部分兼容性,那样才能有希望啊。
0 请登录后投票
   发表时间:2009-08-13  
可以开始写一个Spring的整合了。
0 请登录后投票
   发表时间:2009-08-13  
cats_tiger 写道
可以开始写一个Spring的整合了。


在RC版没有出来之前,一切言之过早,目前User Guide中提到的内容和真实版本的API有差异,应该等稳定了再动手。而且SpringSource的动作一向不慢~~
0 请登录后投票
   发表时间:2009-08-13  
期待出正式版
0 请登录后投票
   发表时间:2009-08-13  

ibatis 3.0中将DAO Interface给完全真空了。

AuthorMapper.class

public interface AuthorMapper {

	Author selectAuthor(int id);

	void insertAuthor(Author author);

	void updateAuthorIfNecessary(Author author);

}

 

AuthorMapper.xml

<mapper namespace="domain.blog.mappers.AuthorMapper">

  <parameterMap id="selectAuthor" type="domain.blog.Author">
    <parameter property="id"/>
  </parameterMap>
   <!-- id 对应接口中的方法 -->
  <resultMap id="selectAuthor" type="domain.blog.Author">
    <id column="id" property="id"/>
    <result property="username" column="username"/>
    <result property="password" column="password"/>
    <result property="email" column="email"/>
    <result property="bio" column="bio"/>
    <result property="favouriteSection" column="favourite_section"/>
  </resultMap>

  <select id="selectAuthor"
          parameterMap="selectAuthor"
          resultMap="selectAuthor">
    select id, username, password, email, bio, favourite_section
    from author where id = ?
  </select>

  <insert id="insertAuthor"
          parameterType="domain.blog.Author">
    insert into Author (id,username,password,email,bio)
    values (#{id},#{username},#{password},#{email},#{bio})
  </insert>

  <update id="updateAuthorIfNecessary"
          parameterType="domain.blog.Author">
    update Author
      <set>
        <if test="username != null">username=#{username},</if>
        <if test="password != null">password=#{password},</if>
        <if test="email != null">email=#{email},</if>
        <if test="bio != null">bio=#{bio}</if>
      </set>
    where id=#{id}
  </update>
</mapper>

   Client:

  

public class SimpleSqlSessionTest {
	private static SqlSessionFactory sqlMapper;

	@Before
	public void setUp() throws Exception {
		final String resource = "org/apache/ibatis/builder/MapperConfig.xml";
		final Reader reader = Resources.getResourceAsReader(resource);
		sqlMapper = new SqlSessionFactoryBuilder().build(reader);
	}

	@Test
	public void shouldSelectOneAuthor() throws Exception {
		SqlSession session = sqlMapper.openSession();
		try {
			Author author = (Author) session.selectOne( "domain.blog.mappers.AuthorMapper.selectAuthor",
					new Author(101));
			assertEquals(101, author.getId());
			assertEquals(Section.NEWS, author.getFavouriteSection());
		} finally {
			session.close();
		}
	}

	@Test
	public void shouldUpdateAuthorIfNecessary() throws Exception {
		SqlSession session = sqlMapper.openSession();
		Author original;
		Author updated;
		try {
			original = (Author) session.selectOne( "domain.blog.mappers.AuthorMapper.selectAuthor", 101);
			original.setEmail("new@email.com");
			original.setBio(null);
			session.update( "domain.blog.mappers.AuthorMapper.updateAuthorIfNecessary", original);

			updated = (Author) session.selectOne( "domain.blog.mappers.AuthorMapper.selectAuthor", 101);
			assertEquals(original.getEmail(), updated.getEmail());
			session.commit();
		} finally {
			session.close();
		}
		
		try {
			session = sqlMapper.openSession();
			updated = (Author) session.selectOne( "domain.blog.mappers.AuthorMapper.selectAuthor", 101);
			assertEquals(original.getEmail(), updated.getEmail());
		} finally {
			session.close();
		}
	}
}

 

 

至于anotations完全是画蛇添足,华而不实。

0 请登录后投票
   发表时间:2009-08-14  
什么好东西用滥了都不好了,anotation在有的地方使用还是方便的。
0 请登录后投票
   发表时间:2009-08-14  
动态SQL增强了
期待它的的稳定
0 请登录后投票
   发表时间:2009-08-15  
弱弱的问下,如果 "".equals(title)类似这样的如何判断,或者num>10这样的条件如何来写呢?
如此来写吗?
<when test=”title != ‘’ ”> 
      AND title like ${title} 
</when> 

<when test=”num>10 ”> 
      AND title like ${title} 
</when> 
0 请登录后投票
   发表时间:2009-08-16  
Spring还没有发布对其新版本的整合,com.ibatis.sqlmap.client.SqlMapClient这个文件不知道在新版本中哪个jar中,貌似新版本中没有找到该类。
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics