在我们编写mybaties的sql操作语句中,通常要涉及到传入的参数类型、以及返回的数据类型给大家看一个例子
<select id="findById" parameterType="int" resultType="user">
select * from user where id=#{id}
</select>
在这个sql语句中就有两个参数类型一个是parameter类型这个类型代表的传入sql语句中的参数类型,sql语句中根据传入的参数进行crud的操作,而resultType则代表着返回的数据类型,这个sql语句会从数据库中查到数据封装成usr类返回该sql语句的调用者。但是值得一说的是返回的类型是要有完全的连包带类的名称的我能写的如此简洁是因为我的sqlMapConfig.xml语句中使用了别名才能把他变得如此的简单。
这个是我的mybaties配置文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!--通过properties标签加载外部properties文件-->
<properties resource="jdbc.properties"></properties>
<!--自定义别名-->
<typeAliases>
<typeAlias type="com.itheima.domain.User" alias="user"></typeAlias>
</typeAliases>
<!--注册类型处理器-->
<typeHandlers>
<typeHandler handler="com.itheima.handler.DateTypeHandler"></typeHandler>
</typeHandlers>
<!--配置分页助手插件-->
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<!-- config params as the following -->
<!--分页参数合理化-->
<property name="reasonable " value="true"/>
</plugin>
</plugins>
<!--数据源环境-->
<environments default="developement">
<environment id="developement">
<transactionManager type="JDBC"></transactionManager>
<dataSource type="POOLED">
<property name="driver" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</dataSource>
</environment>
</environments>
<!--加载映射文件-->
<mappers>
<mapper resource="com/itheima/mapper/UserMapper.xml"></mapper>
</mappers>
</configuration>
在<typeAliases>这个标签中我设置了别名这个user映射着的就是com.itheima.domain.User这个类