300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > SSM之一点一滴:mybatis parameterType传入类型 resultType返回类型

SSM之一点一滴:mybatis parameterType传入类型 resultType返回类型

时间:2019-05-23 23:24:47

相关推荐

SSM之一点一滴:mybatis parameterType传入类型   resultType返回类型

一、parameterType参数传入类型

概述:

parameterType传入参数类型可以为int,String,Integer,Date,java实体类,map等,下面的用法中采用的是parameterType="com.huawei.model.Person" java实体类型

二、resultType数据返回类型

概述:

resultType数据返回类型可以为int,String,Integer,Date,java实体类,map,list 等下面的用法中采用的是resultType="com.huawei.model.Person" java实体类型

三、用法

在dao接口

package com.huawei.dao;import com.huawei.model.Person;public interface PersonMapper {/*** 查询所有* @return*/Person queryAll(Person person);}

queryAll为mapping映射文件的id,唯一标识符

queryAll方法前面的Person为resultType数据返回类型,即在mapping中的resultType="com.huawei.model.Person" java实体类型

queryAll方法参数中Person为parameterType参数传入类型,即在mapping中的parameterType="com.huawei.model.Person" java实体类型

mapping映射基本配置解释如下

<!-- 为这个mapper指定一个唯一的namespace,namespace的值习惯上设置成包名+sql映射文件名,这样就能够保证namespace的值是唯一的。例如namespace="com.huawei.dao.PersonMapper"就是com.huawei.dao(包名)+PersonMapper(PersonMapper.xml文件去除后缀) --><mapper namespace="com.huawei.dao.PersonMapper"><select id="queryAll" parameterType="com.huawei.model.Person" resultType="com.huawei.model.Person" > select * from person </select><!-- 1. id (必须配置)id是命名空间中的唯一标识符,可被用来代表这条语句。一个命名空间(namespace) 对应一个dao接口这个id也应该对应dao里面的某个方法(相当于方法的实现),因此id 应该与方法名一致 --><!-- 2. parameterType (可选配置, 默认为mybatis自动选择处理)将要传入语句的参数的完全限定类名或别名, 如果不配置,mybatis会通过ParameterHandler 根据参数类型默认选择合适的typeHandler进行处理parameterType 主要指定参数类型,可以是int, short, long, string等类型,也可以是复杂类型(如对象)即"com.huawei.model.Person" --><!-- 3. resultType (resultType 与 resultMap 二选一配置)resultType用以指定返回类型,指定的类型可以是基本类型可以是int, short, long, string等,可以是java容器,也可以是javabean 如在下面的配置中采用的是Person实体对象的返回类型--><!-- 4. resultMap (resultType 与 resultMap 二选一配置)resultMap用于引用我们通过 resultMap标签定义的映射类型,这也是mybatis组件高级复杂映射的关键 --><!-- 5. flushCache (可选配置)将其设置为 true,任何时候只要语句被调用,都会导致本地缓存和二级缓存都会被清空,默认值:false flushCache="false"--><!-- 6. useCache (可选配置)将其设置为 true,将会导致本条语句的结果被二级缓存,默认值:对 select 元素为 true useCache="true"--><!-- 7. timeout (可选配置) 这个设置是在抛出异常之前,驱动程序等待数据库返回请求结果的秒数。默认值为 unset(依赖驱动) timeout="10000"--><!-- 8. fetchSize (可选配置) 这是尝试影响驱动程序每次批量返回的结果行数和这个设置值相等。默认值为 unset(依赖驱动) fetchSize="256"--><!-- 9. statementType (可选配置) STATEMENT,PREPARED 或 CALLABLE 的一个。这会让 MyBatis 分别使用 Statement,PreparedStatement 或 CallableStatement,默认值:PREPARED statementType="PREPARED" --><!-- 10. resultSetType (可选配置) FORWARD_ONLY,SCROLL_SENSITIVE 或 SCROLL_INSENSITIVE 中的一个,默认值为 unset (依赖驱动) resultSetType="FORWARD_ONLY"--></mapper>

参考链接:/dongying/p/4073259.html

具体深入请百度关键词

mybatis parameterType

mybatis resultType

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。