第1个回答 2016-04-02
1.以前用的parameterClass在mybatis中已经永不了了,mybatis里应该使用parameterType。另外resultMap里面也不能继续使用了改成了type
2.dynamic标签不能使用了,下面的配置在mybatis里是错的
[html] view plaincopy
<sql id="sqlwhere">
<dynamic>
<isGreaterThan prepend="and" property="FPARENTID" compareValue="-1">
A.FPARENTID = #FPARENTID#
</isGreaterThan>
<isNotEmpty prepend="and" property="LOGINTOPIMAGE">
A.LOGINTOPIMAGE like #LOGINTOPIMAGE#
</isNotEmpty>
<isGreaterThan prepend="and" property="FID" compareValue="-1">
A.FID = #FID#
</isGreaterThan>
<isNotEmpty prepend="and" property="FNAME">
A.FNAME like #FNAME#
</isNotEmpty>
<isNotEmpty prepend="and" property="LOGINMIDDLEIMAGE">
A.LOGINMIDDLEIMAGE like #LOGINMIDDLEIMAGE#
</isNotEmpty>
<isNotEmpty prepend="and" property="VERSIONNUMBER">
A.VERSIONNUMBER like #VERSIONNUMBER#
</isNotEmpty>
<isNotEmpty prepend="and" property="MAJORTITLE">
A.MAJORTITLE like #MAJORTITLE#
</isNotEmpty>
<isNotEmpty prepend="and" property="LOGINTITLE">
A.LOGINTITLE like #LOGINTITLE#
</isNotEmpty>
<isNotEmpty prepend="and" property="MAJORMIDDLEIMAGE">
A.MAJORMIDDLEIMAGE like #MAJORMIDDLEIMAGE#
</isNotEmpty>
<isNotEmpty prepend="and" property="LOGINBOTTOMIMAGE">
A.LOGINBOTTOMIMAGE like #LOGINBOTTOMIMAGE#
</isNotEmpty>
<isNotEmpty prepend="and" property="MAJORTOPIMAGE">
A.MAJORTOPIMAGE like #MAJORTOPIMAGE#
</isNotEmpty>
<isNotEmpty prepend="and" property="LOGO">
A.LOGO like #LOGO#
</isNotEmpty>
<isNotEmpty prepend="and" property="LOGO">
A.ADDRESS like #ADDRESS#
</isNotEmpty>
<isNotEmpty prepend="and" property="LOGO">
A.FAX like #FAX#
</isNotEmpty>
<isNotEmpty prepend="and" property="LOGO">
A.PHONE like #PHONE#
</isNotEmpty>
<isNotEmpty prepend="and" property="LOGO">
A.ZIP like #ZIP#
</isNotEmpty>
<isNotEmpty prepend="and" property="LOGO">
A.EMAIL like #EMAIL#
</isNotEmpty>
<isNotEmpty prepend="and" property="containIds">
A.FID NOT IN ($containIds$)
</isNotEmpty>
</dynamic>
</sql>
3.数据类型的声明和ibatis有了很大的差别,ibatis可以像下面这样写
[html] view plaincopy
insert into M_HEALTHSPECIALYTYPE(FCODE,FCHARGE,FTYPECONTENT,FID,FMARK)
values (#FCODE:VARCHAR2#,#FCHARGE:VARCHAR2#,#FTYPECONTENT:VARCHAR2#,#FID#,#FMARK:VARCHAR2#)
在mybatis的话一般是这样弄的
[html] view plaincopy
insert into M_HEALTHSPECIALYTYPE(FCODE,FCHARGE,FTYPECONTENT,FID,FMARK)
values (#{FCODE,jdbcType=VARCHAR},#{FCHARGE,jdbcType=VARCHAR},#{FTYPECONTENT,jdbcType=VARCHAR},#{FID},#{FMARK,jdbcType=VARCHAR})
4.mybatis现在已经没有SqlMapClient了,使用的则是SqlSession.在原来的基础上加了像selectMap,selectList,selectOne这样的方法,使用更方便了
5.加了一个叫映射器的新东西,只需要写出接口而不需要实现类就能够操作数据如
[html] view plaincopy
import java.util.List;
import org.lxh.vo.HealthspecialytypeInfo;
public interface HealthMapper {
public List<HealthspecialytypeInfo> getRecordByList(HealthspecialytypeInfo info);
}
在映射文件里要记得namespace写成接口的类全名,sql语句的id写成接口里的方法名就可以了
[html] view plaincopy
<select id="getRecordByList" parameterType="org.lxh.vo.HealthspecialytypeInfo" resultMap="resultMap">
select * from M_HEALTHSPECIALYTYPE where FCODE in
<foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
调用的时候就像下面
[java] view plaincopy
HealthMapper m=ses.getMapper(HealthMapper.class);
List<HealthspecialytypeInfo> record=m.getRecordByList(h);
就这样就可以直接进行数据的操作了,的确智能了很多本回答被提问者采纳