<?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> <!-- 命名空间 --> <typeAliases> <typeAlias alias="CompanyInfoVO" type="dao.vos.CompanyInfoVO"/> <typeAlias alias="MeetingInfoVO" type="dao.vos.MeetingInfoVO"/> <typeAlias alias="CompanyMeetingsInfoVO" type="dao.vos.CompanyMeetingsInfoVO"/> <typeAlias alias="ParticipatesVO" type="dao.vos.ParticipatesVO"/> <typeAlias alias="CandidatesVO" type="dao.vos.CandidatesVO"/> <typeAlias alias="DayMeetingsVO" type="dao.vos.DayMeetingsVO"/> </typeAliases> <!-- 映射map --> <mappers> </mappers> </configuration>
mybatis-config文件里面的typeAliases标签的作用是 写实体类的别名,写了之后,在写sql的配置文件里面,例如<select>标签中的属性就可以不用写实体类的具体路径,直接用别名就行。实际例子:
没有写别名的时候,这样写
<select resultType="dao.vos.MeetingInfoVO">
写了别名,如上mybatis-config配置文件第二个,写法如下
<select resultType = "MeetingInfoVO">
直接写别名就可以了,不用写实体类的具体路径。"MeetingInfoVO"就能代替"dao.vos.MeetingInfoVO"在任何地方使用。
下面是用到别名的地方,
<resultMap type="CompanyMeetingsInfoVO" id="resultListCompanyMeetingsInfoVO">
返回的map类型对象是CompanyMeetingInfoVO,这个对象的地址是dao.vos.CompanyMeetingInfoVO,即返回的是这个路径下面的这个对象。
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="dao.mappers.CompanyMeetingsMapper"> <!--返回list类型定义,返回会议部分--> <resultMap type="CompanyMeetingsInfoVO" id="resultListCompanyMeetingsInfoVO"> <id column="id" property="meeting_id" /> <result column="meeting_id" property="meeting_id" /> <result column="meeting_topic" property="meeting_topic" /> <result column="company_id" property="company_id" /> <result column="host_id" property="host_id" /> <result column="start_time" property="start_time" /> <result column="end_time" property="end_time" /> </resultMap> <!--返回list类型定义,返回参与者部分--> <resultMap type="ParticipatesVO" id="resultListParticipatesVO"> <id column="id" property="meeting_id" /> <result column="meeting_id" property="meeting_id" /> <result column="userId" property="user_id" /> <result column="user_name" property="user_name" /> <result column="user_position" property="user_position" /> <result column="head_icon" property="head_icon" /> </resultMap> <!--返回list类型定义,返回候选者部分--> <resultMap type="CandidatesVO" id="resultListCandidatesVO"> <id column="id" property="user_id" /> <result column="user_id" property="user_id" /> <result column="user_name" property="user_name" /> <result column="user_position" property="user_position" /> <result column="head_icon" property="head_icon" /> </resultMap> <!--调用存储过程,一个输入,三个输出--> <select id="getAllMeetings" statementType="CALLABLE" parameterType="java.util.Map"> {call GetCompanyAllMeetings(#{companyId,jdbcType=INTEGER,mode=IN}, #{userId,jdbcType=CHAR,mode=IN}, #{allMeetings,jdbcType=CURSOR,mode=OUT,resultMap=resultListCompanyMeetingsInfoVO}, #{participants,jdbcType=CURSOR,mode=OUT,resultMap=resultListParticipatesVO}, #{candidates,jdbcType=CURSOR,mode=OUT,resultMap=resultListCandidatesVO}, #{errorNumber,jdbcType=INTEGER,mode=OUT})} </select> </mapper>