mybatis 比 ibatis 改进了很多,特别是支持了注解,支持了plugin inteceptor,也给开发者带来了更多的灵活性,相比其他ORM,我还是挺喜欢mybatis的. 闲言碎语不要讲,今天研究了下mybatis的typeHandler: 先看这样一张表(postgresql) create table user ( id serial not null name ), age integer, emails character varchar[], -- varchar 数组 表
mybatis动态拼装sql详情 MyBatis的动态SQL是基于OGNL表达式的,它可以帮助我们方便的在SQL语句中实现某些逻辑. MyBatis中用于实现动态SQL的元素主要有: if choose(when,otherwise) trim where set foreach bind <if>元素 在mybatis中if是最常用的判断语句,用来进行一些简单的判断,然后进行动态sql的拼接. <select id="dynamicIfTest" parameter
有时候开发中需要根据多个ID去查询,可以将ID封装为List或者数组然后使用MyBatis中的foreach标签构建in条件. 这里我将ID封装为String[]作为参数. <select id="selectList" parameterType="java.util.List" resultType="java.lang.Integer"> SELECT COUNT(1) FROM t_user WHERE id IN <f