1.懒加载配置
View Code
<?xml version="1.0" encoding="UTF-8" ?>
<sqlMap namespace="PowerDayData" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<alias>
<typeAlias alias="PowerDayData" type="Cn.Loosoft.Zhisou.SunPower.Domain.PowerDayData, Domain" />
<typeAlias alias="PowerDayDataDetail" type="Cn.Loosoft.Zhisou.SunPower.Domain.PowerDayDataDetail, Domain" />
</alias>
<resultMaps>
<resultMap id="PowerDayDataResult" class="PowerDayData">
<result property="Id" column="Id"/>
<result property="deviceId" column="deviceId"/>
<result property="SendDate" column="sendDate"/>
<result property="DayPower" column="DayPower"/>
<result property="Details" keyProperty="plantId" lazyLoad="true" column="deviceId" select="SELECT_PLANT_DAYDATA_DETAIL" />-->
</resultMap>
<resultMap id="PowerDayDataDetailResult" class="PowerDayDataDetail">
<result property="Id" column="Id"/>
<result property="deviceId" column="deviceId"/>
<result property="SendDate" column="sendDate"/>
<result property="SendTime" column="SendTime"/>
<result property="SendValue" column="SendValue"/>
</resultMap>
</resultMaps>
<statements>
<select id="POWERDAYDATA_GET" resultMap="PowerDayDataResult" >
SELECT * FROM power_day_data
</select>
<select id="SELECT_PLANT_DAYDATA_DETAIL" resultMap="PowerDayDataDetailResult" >
SELECT * FROM power_day_data_detail
</select>
</statements>
</sqlMap>
<sqlMap namespace="PowerDayData" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<alias>
<typeAlias alias="PowerDayData" type="Cn.Loosoft.Zhisou.SunPower.Domain.PowerDayData, Domain" />
<typeAlias alias="PowerDayDataDetail" type="Cn.Loosoft.Zhisou.SunPower.Domain.PowerDayDataDetail, Domain" />
</alias>
<resultMaps>
<resultMap id="PowerDayDataResult" class="PowerDayData">
<result property="Id" column="Id"/>
<result property="deviceId" column="deviceId"/>
<result property="SendDate" column="sendDate"/>
<result property="DayPower" column="DayPower"/>
<result property="Details" keyProperty="plantId" lazyLoad="true" column="deviceId" select="SELECT_PLANT_DAYDATA_DETAIL" />-->
</resultMap>
<resultMap id="PowerDayDataDetailResult" class="PowerDayDataDetail">
<result property="Id" column="Id"/>
<result property="deviceId" column="deviceId"/>
<result property="SendDate" column="sendDate"/>
<result property="SendTime" column="SendTime"/>
<result property="SendValue" column="SendValue"/>
</resultMap>
</resultMaps>
<statements>
<select id="POWERDAYDATA_GET" resultMap="PowerDayDataResult" >
SELECT * FROM power_day_data
</select>
<select id="SELECT_PLANT_DAYDATA_DETAIL" resultMap="PowerDayDataDetailResult" >
SELECT * FROM power_day_data_detail
</select>
</statements>
</sqlMap>
2.连接Mysql 数据库
<database>
<provider name="MySql" />
<dataSource name="MySql" connectionString="server=192.168.0.133;port=3306;user id=root;password=;database=sunInfoBank;CharSet=utf8;allow zero datetime=true;Convert Zero Datetime=true;" />
</database>
<provider name="MySql" />
<dataSource name="MySql" connectionString="server=192.168.0.133;port=3306;user id=root;password=;database=sunInfoBank;CharSet=utf8;allow zero datetime=true;Convert Zero Datetime=true;" />
</database>
3. 返回数据库自增列 MYSQL数据库
<insert id="USERINFO_INSERT">
INSERT INTO USERINFO(UserName,PassWord,Organize,Sex,FullName,Address,City,Country,Tel,LanguageId) VALUES(#UserName#,#PassWord#,#Organize#,#Sex#,#FullName#,#Address#,#City#,#Country#,#Tel#,#Language#);
<selectKey resultClass="int" property="Id" type="pre" > SELECT LAST_INSERT_ID() AS ID
</selectKey>
</insert>
INSERT INTO USERINFO(UserName,PassWord,Organize,Sex,FullName,Address,City,Country,Tel,LanguageId) VALUES(#UserName#,#PassWord#,#Organize#,#Sex#,#FullName#,#Address#,#City#,#Country#,#Tel#,#Language#);
<selectKey resultClass="int" property="Id" type="pre" > SELECT LAST_INSERT_ID() AS ID
</selectKey>
</insert>
4. ibatis.net 复杂属性
View Code
<resultMap id="com2result" class="Account" >
<result property="Id" column="Account_ID"/>
<result property="FirstName" column="Account_FirstName"/>
<result property="LastName" column="Account_LastName"/>
<result property="EmailAddress" column="Account_Email" nullValue="no_email@provided.com"/>
<result property="Degree" resultMapping="Account.Degree-result"/>
</resultMap>
<resultMap id="Degree-result" class="Degree">
<result property="Id" column="Account_ID"/>
<result property="DegreeName" column="DegreeName"/>
</resultMap>
<result property="Id" column="Account_ID"/>
<result property="FirstName" column="Account_FirstName"/>
<result property="LastName" column="Account_LastName"/>
<result property="EmailAddress" column="Account_Email" nullValue="no_email@provided.com"/>
<result property="Degree" resultMapping="Account.Degree-result"/>
</resultMap>
<resultMap id="Degree-result" class="Degree">
<result property="Id" column="Account_ID"/>
<result property="DegreeName" column="DegreeName"/>
</resultMap>
5. PS:
SQLMAP命名空间引用 有先后顺序 如果a.xml 引用了b.xml的名称空间
那么sqlmap配置的时候b.xml必须放到a.xml的前面