<?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>標籤中的屬性就能夠不用寫實體類的具體路徑,直接用別名就行。實際例子:
java
沒有寫別名的時候,這樣寫sql
<select resultType="dao.vos.MeetingInfoVO">mybatis
寫了別名,如上mybatis-config配置文件第二個,寫法以下app
<select resultType = "MeetingInfoVO">spa
直接寫別名就能夠了,不用寫實體類的具體路徑。"MeetingInfoVO"就能代替"dao.vos.MeetingInfoVO"在任何地方使用。code
下面是用到別名的地方,xml
<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>