首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

ibatis3 beta 一 发布,新功能介绍

2012-10-29 
ibatis3 beta 1 发布,新功能介绍ibatis 3 beta 1 发布,可以去下载试用一下了,http://ibatis.apache.org/ja

ibatis3 beta 1 发布,新功能介绍

ibatis 3 beta 1 发布,可以去下载试用一下了,http://ibatis.apache.org/java.cgi?Preferred=http://www.apache.org/dist

?

大概读了一下User Guide,值得关注的几点:

* Namespace 现在不是optional了,是required

* 可以使用Java Annotation来配置这些sql了,不过由于java本身和annotation本身的限制,更复杂的sql还是建议使用xml

* 强类型的接口(interface binding),可以使用:

?

    <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>
&lt;/mapper&gt;</pre>
<p>?? Client:</p>
<p>?? </p>
<pre name="code" class="java">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();
}
}
}</pre>
<p>?</p>
<p>?</p>
<p>至于anotations<span style="">完全是画蛇添足,华而不实。</span></p> 16 楼 zeroxin 2009-08-14   什么好东西用滥了都不好了,anotation在有的地方使用还是方便的。 17 楼 lixjluck 2009-08-14   动态SQL增强了
期待它的的稳定 18 楼 moss 2009-08-15   弱弱的问下,如果 "".equals(title)类似这样的如何判断,或者num>10这样的条件如何来写呢?
如此来写吗?
<when test=”title != ‘’ ”> 
      AND title like ${title} 
</when> 

<when test=”num>10 ”> 
      AND title like ${title} 
</when>  19 楼 jones_ahk 2009-08-16   Spring还没有发布对其新版本的整合,com.ibatis.sqlmap.client.SqlMapClient这个文件不知道在新版本中哪个jar中,貌似新版本中没有找到该类。 20 楼 totobacoo 2009-08-16   Spring 还没跟上,暂时只有等待 21 楼 jones_ahk 2009-08-17   下载了IBatis3的源码,编译通过后,结合Spring2.5,发现原来IBatis2中的一些class都不存在了,不知道是什么原因??
由于IBatis3与2的区别太大了,现在想用2吧又不敢(后续升级简直太困难了),不用2吧3又不稳定,而且与Spring集成有问题,现在都不知道咋办了!!
22 楼 argan 2009-08-17   jones_ahk 写道下载了IBatis3的源码,编译通过后,结合Spring2.5,发现原来IBatis2中的一些class都不存在了,不知道是什么原因??
由于IBatis3与2的区别太大了,现在想用2吧又不敢(后续升级简直太困难了),不用2吧3又不稳定,而且与Spring集成有问题,现在都不知道咋办了!!


ibatis3 现在还是beta,不建议在生产环境中使用,当然如果愿意承担一些风险另说 23 楼 lnaigg 2009-08-18   一向对anotation不感兴趣,对动态SQL感兴趣。

不过不明白动态SQL这部分为什么不直接用模版语言实现(velocity或freemarker).
现在的风格像XSL,比较笨拙,看着累。 24 楼 lggege 2009-09-18   1. 我一直都觉得没必要写一个DAO impl类, 太麻烦了, 还不如直接使用DAO的方法名去SQL-MAP文件去找呢.

2. 我也认为namespace没有那么必要, 可以直接使用DAO的类名. 25 楼 lixjluck 2009-09-24   jones_ahk 写道下载了IBatis3的源码,编译通过后,结合Spring2.5,发现原来IBatis2中的一些class都不存在了,不知道是什么原因??
由于IBatis3与2的区别太大了,现在想用2吧又不敢(后续升级简直太困难了),不用2吧3又不稳定,而且与Spring集成有问题,现在都不知道咋办了!!


3不兼容2的,且spring目前也不支持3
如项目用,那就先用2.3的版本吧
26 楼 raymond2006k 2009-09-27   ibatis 3 貌似对 SessionFactory 也支持了,向 Hibernate,toplink 等架构靠拢了。

ibatis 对分布式缓存支持的不太好,希望能有实质性的改进。 27 楼 reniaL 2009-09-29   出来后有简单试用了一下。

文档还不完善,甚至有错误的地方(例如hyxw5890说的resultType和resultClass的问题),新人的话还是先用2吧,毕竟现在3还是beta。

还有那个iBatis Migrations,用来管理数据库变更的,感觉跟ROR的模式很像,不过功能也忒简单了点,还不实用。

希望正式版能有所改进吧~ 28 楼 tobackfurture 2009-10-29   要不我们一起把文档给翻译了吧,一人一张!
中不? 29 楼 kaki 2010-02-20   Spring2.5 还是不支持啊!郁闷中! 30 楼 luoxj 2010-04-06   3是否有解决1:M和M:N的问题了。 31 楼 bluethink 2010-07-04   还没用过,正要试试 32 楼 evaspring 2010-07-21   分页机制是否增强了? 33 楼 hst1189 2010-08-06   evaspring 写道是否增强了?

同问分页机制 ?

热点排行