最近开发过程中遇到几个ibatis的问题
1.cxf定义的date类型的数据ibatis无法直接处理
1)wsdl中申明为xsd:date或xsd:datetime,转换成java对象后成为XMLGregorianCalendar类型
2)使用ibatis的TypeHandler进行类型的转换,如:
<resultMap class="com.acconsys.alms.user.User" id="userResultMap">
<result property="userId" column="user_id"/>
<result property="loginName" column="login_name"/>
<result property="gender" column="gender"/>
<result property="email" column="email"/>
<result property="address" column="address"/>
<result property="birthday" column="birthday" typeHandler="com.acconsys.alms.util.XMLGregorianCalendarTypeHandler" />
</resultMap>
<select id="login" parameterClass="map" resultMap="userResultMap" >
select * from alms_user
where login_name=#loginName:VARCHAR#
and password=#password:VARCHAR#
</select>
2.ibatis的insert语句使用parameterMap的问题
<parameterMap id="insertEventMap" class="com.acconsys.alms.event.Event">
<parameter property="id" javaType="long" />
<parameter property="name" jdbcType="VARCHAR" javaType="java.lang.String" />
<parameter property="occurTime" typeHandler="com.acconsys.alms.util.XMLGregorianCalendarTypeHandler"/>
</parameterMap>
<insert id="insertEvent" parameterMap="insertEventMap">
<selectKey resultClass="long" keyProperty="id">
select event_id_seq.nextval as id from dual
</selectKey>
insert into event(event_id, name, occur_time) values (?, ?, ?)
</insert>
需要注意2点
1)insert into语句最后不能有分号";",否则会报java.sql.SQLException: ORA-00911: 无效字符
2)每个参数使用疑问号做占位符
1.cxf定义的date类型的数据ibatis无法直接处理
1)wsdl中申明为xsd:date或xsd:datetime,转换成java对象后成为XMLGregorianCalendar类型
2)使用ibatis的TypeHandler进行类型的转换,如:
<resultMap class="com.acconsys.alms.user.User" id="userResultMap">
<result property="userId" column="user_id"/>
<result property="loginName" column="login_name"/>
<result property="gender" column="gender"/>
<result property="email" column="email"/>
<result property="address" column="address"/>
<result property="birthday" column="birthday" typeHandler="com.acconsys.alms.util.XMLGregorianCalendarTypeHandler" />
</resultMap>
<select id="login" parameterClass="map" resultMap="userResultMap" >
select * from alms_user
where login_name=#loginName:VARCHAR#
and password=#password:VARCHAR#
</select>
2.ibatis的insert语句使用parameterMap的问题
<parameterMap id="insertEventMap" class="com.acconsys.alms.event.Event">
<parameter property="id" javaType="long" />
<parameter property="name" jdbcType="VARCHAR" javaType="java.lang.String" />
<parameter property="occurTime" typeHandler="com.acconsys.alms.util.XMLGregorianCalendarTypeHandler"/>
</parameterMap>
<insert id="insertEvent" parameterMap="insertEventMap">
<selectKey resultClass="long" keyProperty="id">
select event_id_seq.nextval as id from dual
</selectKey>
insert into event(event_id, name, occur_time) values (?, ?, ?)
</insert>
需要注意2点
1)insert into语句最后不能有分号";",否则会报java.sql.SQLException: ORA-00911: 无效字符
2)每个参数使用疑问号做占位符