Ibatis查询主从表问题 有一个主表对象,从表作为它的明细属性.怎样在查主表对象时,把它的明细也带出来? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 需要在XML文件里配置的.等下给你发代码 用datarelation 可以解决lz可以找找相关实例 <?xml version="1.0" encoding="utf-8" ?><sqlMap namespace="Service.BO" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <alias> <typeAlias alias="Role" type="Service.BO.Role, Service" /> </alias> <resultMaps> <resultMap id="RoleResult" class="Role"> <result property="Id" column="Id" /> <result property="Name" column="Name" /> <result property="Description" column="Description" /> <result property ="Popedom" select="SelectPopedomByRoleId" column="Id"/> <result property ="Users" lazyLoad="true" select="SelectUsersByRoleId" column="Id"/> </resultMap> </resultMaps> <statements> <select id="SelectRole" parameterClass="string" resultMap="RoleResult"> select Id, Name, Description from Role <dynamic prepend="WHERE"> <isParameterPresent> Id = #value# </isParameterPresent> </dynamic> </select> <select id="SelectRoleByRoleName" parameterClass="string" resultMap="RoleResult"> select Id, Name, Description from Role <dynamic prepend="WHERE"> <isParameterPresent> Name = #value# </isParameterPresent> </dynamic> </select> <select id="SelectPopedomByRoleId" parameterClass="string" resultClass="Service.BO.Popedom"> select p.Code, p.PopedomName, p.Description, p.ParentCode,p.Flag from Popedom p,RolePopedom rp where rp.PopedomCode = p.Code and rp.RoleId = #Id# </select> <select id="SelectUsersByRoleId" parameterClass="string" resultClass="Service.BO.UserInfo"> select ui.Id, Name, Password, ShortName, Sex, BirthDate, Duty, OfficialPhone, Fax, MobilePhone, Email, Sequence, IsDirector, Re, Flag, DepartmentCode, InfoCheckedNumber from UserInfo ui, RoleUser ru where ru.UserId = ui.Id and ru.RoleId = #Id# order by ui.DepartmentCode,ui.Sequence </select> <select id="SelectAllRole" resultMap="RoleResult"> select Id, Name, Description from Role </select> <insert id="InsertRole" parameterClass="Role"> insert into Role (Id, Name, Description) values (#Id#, #Name#, #Description#) </insert> <update id="UpdateRole" parameterClass="Role"> update Role set Name = #Name#, Description = #Description# where Id = #Id# </update> <delete id="DeleteRole" parameterClass="string"> delete from Role where Id = #value# </delete> </statements></sqlMap>Role表 <?xml version="1.0" encoding="utf-8" ?><sqlMap namespace="Service.BO" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <alias> <typeAlias alias="UserInfo" type="Service.BO.UserInfo, Service" /> </alias> <resultMaps> <resultMap id="UserInfoResult" class="UserInfo"> <result property="Id" column="Id" ></result> <result property="Name" column="Name" ></result> <result property="Password" column="Password" ></result> <result property="LogOnName" column="LogOnName" ></result> <result property="Sex" column="Sex" ></result> <result property="BirthDate" column="BirthDate" ></result> <result property="Duty" column="Duty" ></result> <result property="OfficialPhone" column="OfficialPhone" ></result> <result property="Fax" column="Fax" ></result> <result property="MobilePhone" column="MobilePhone" ></result> <result property="Email" column="Email" ></result> <result property="Sequence" column="Sequence" ></result> <result property="IsDirector" column="IsDirector" ></result> <result property="Re" column="Re" ></result> <result property="Flag" column="Flag" ></result> <result property="DepartmentCode" column="DepartmentCode" /> <result property ="Popedom" lazyLoad="true" select="SelectPopedomById" column="Id" ></result> </resultMap> </resultMaps> <statements> <select id="SelectUserInfo" parameterClass="string" resultMap="UserInfoResult"> select Id, Name, Password, LogOnName, Sex, BirthDate, Duty, OfficialPhone, Fax, MobilePhone, Email, Sequence, IsDirector, Re, Flag, DepartmentCode<!--, InfoCheckedNumber--> from UserInfo <dynamic prepend="WHERE"> <isParameterPresent> Id = #value# </isParameterPresent> </dynamic> </select> <select id="SelectUserInfoByLoginName" parameterClass="string" resultMap="UserInfoResult"> select Id, Name, Password, LogOnName, Sex, BirthDate, Duty, OfficialPhone, Fax, MobilePhone, Email, Sequence, IsDirector, Re, Flag, DepartmentCode<!--, InfoCheckedNumber--> from UserInfo <dynamic prepend="WHERE"> <isParameterPresent> LogOnName = #value# </isParameterPresent> </dynamic> </select> <select id="SelectAllUserInfo" resultMap="UserInfoResult"> select Id, Name, Password, LogOnName, Sex, BirthDate, Duty, OfficialPhone, Fax, MobilePhone, Email, Sequence, IsDirector, Re, Flag, DepartmentCode<!--, InfoCheckedNumber--> from UserInfo order by DepartmentCode,Sequence </select> <select id="SelectUserByDepCode" parameterClass="string" resultMap="UserInfoResult"> select Id, Name, Password, LogOnName, Sex, BirthDate, Duty, OfficialPhone, Fax, MobilePhone, Email, Sequence, IsDirector, Re, Flag, DepartmentCode<!--, InfoCheckedNumber--> from UserInfo <dynamic prepend="WHERE"> <isParameterPresent> DepartmentCode = #value# </isParameterPresent> </dynamic> order by Sequence </select> <select id="SelectChildUserByCode" parameterClass="string" resultMap="UserInfoResult"> select Id, Name, Password, LogOnName, Sex, BirthDate, Duty, OfficialPhone, Fax, MobilePhone, Email, Sequence, IsDirector, Re, Flag, DepartmentCode<!--, InfoCheckedNumber--> from UserInfo <dynamic prepend="WHERE"> <isParameterPresent> DepartmentCode like #value# </isParameterPresent> </dynamic> order by Sequence </select> <select id="SelectPopedomById" parameterClass="string" resultClass="Service.BO.Popedom"> select distinct Popedom.PopedomName,Popedom.Description,Popedom.Code from Popedom, RolePopedom, RoleUser, UserInfo where UserInfo.ID = RoleUser.UserID and RoleUser.RoleID = RolePopedom.RoleID and RolePopedom.PopedomCode = Popedom.Code and UserInfo.ID=#Id# </select> <insert id="InsertUserInfo" parameterClass="UserInfo"> insert into UserInfo (Id, Name, [Password], LogOnName, Sex, BirthDate, Duty, OfficialPhone, Fax, MobilePhone, Email, Sequence, IsDirector, Re, Flag, DepartmentCode) values(#Id#, #Name#, #Password#, #LogOnName#, #Sex#, #BirthDate#, #Duty#, #OfficialPhone#, #Fax#, #MobilePhone#, #Email#, #Sequence#, #IsDirector#, #Re#, #Flag#, #DepartmentCode#) </insert> <update id="UpdateUserInfo" parameterClass="UserInfo"> update UserInfo set Name = #Name#, [Password] = #Password#, LogOnName = #LogOnName#, Sex = #Sex#, BirthDate = #BirthDate#, Duty = #Duty#, OfficialPhone = #OfficialPhone#, Fax = #Fax#, MobilePhone = #MobilePhone#, Email = #Email#, Sequence = #Sequence#, IsDirector = #IsDirector#, Re = #Re#, Flag = #Flag#, DepartmentCode = #DepartmentCode# where Id = #Id# </update> <delete id="DeleteUserInfo" parameterClass="string"> delete from UserInfo where Id = #value# </delete> </statements></sqlMap>UserInfo表这里面有这两者的关系. DateTimePicker控件的tab顺序问题 折腾了几天了,只好到这里求助了,关于Windows服务进程调用EUDC自定义字符的问题。 c# 设置系统时间 帮看下这段代码是否有问题? varbinary(max)对应的net类型是什么 c#异步操作的问题 请教大家一个关于搜索引擎的问题,谢谢 请问如何自动填写模式对话框形式的网页表单啊? 海波大哥和诸位水晶报表高手过来帮忙啊!水晶报表中如何让详细资料区的内容一直打印到页面的底部!内详 如何使用COM10以上 C#里有没有统计一个字符在另一个字符串中出现的次数的函数? 记事本的按键功能? 求救 在线等
lz可以找找相关实例
<sqlMap namespace="Service.BO" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<alias>
<typeAlias alias="Role" type="Service.BO.Role, Service" />
</alias>
<resultMaps>
<resultMap id="RoleResult" class="Role">
<result property="Id" column="Id" />
<result property="Name" column="Name" />
<result property="Description" column="Description" />
<result property ="Popedom" select="SelectPopedomByRoleId" column="Id"/>
<result property ="Users" lazyLoad="true" select="SelectUsersByRoleId" column="Id"/>
</resultMap>
</resultMaps>
<statements>
<select id="SelectRole" parameterClass="string" resultMap="RoleResult">
select Id, Name, Description
from Role
<dynamic prepend="WHERE">
<isParameterPresent>
Id = #value#
</isParameterPresent>
</dynamic>
</select>
<select id="SelectRoleByRoleName" parameterClass="string" resultMap="RoleResult">
select Id, Name, Description
from Role
<dynamic prepend="WHERE">
<isParameterPresent>
Name = #value#
</isParameterPresent>
</dynamic>
</select>
<select id="SelectPopedomByRoleId" parameterClass="string" resultClass="Service.BO.Popedom">
select p.Code, p.PopedomName, p.Description, p.ParentCode,p.Flag
from Popedom p,RolePopedom rp
where rp.PopedomCode = p.Code and
rp.RoleId = #Id#
</select>
<select id="SelectUsersByRoleId" parameterClass="string" resultClass="Service.BO.UserInfo">
select ui.Id, Name, Password, ShortName, Sex, BirthDate, Duty, OfficialPhone, Fax, MobilePhone, Email, Sequence, IsDirector, Re, Flag, DepartmentCode, InfoCheckedNumber
from UserInfo ui, RoleUser ru
where ru.UserId = ui.Id and
ru.RoleId = #Id#
order by ui.DepartmentCode,ui.Sequence
</select>
<select id="SelectAllRole" resultMap="RoleResult">
select Id, Name, Description
from Role
</select>
<insert id="InsertRole" parameterClass="Role">
insert into Role (Id, Name, Description)
values
(#Id#, #Name#, #Description#)
</insert>
<update id="UpdateRole" parameterClass="Role">
update Role set
Name = #Name#,
Description = #Description#
where Id = #Id#
</update>
<delete id="DeleteRole" parameterClass="string">
delete from Role
where Id = #value#
</delete>
</statements>
</sqlMap>Role表
<?xml version="1.0" encoding="utf-8" ?>
<sqlMap namespace="Service.BO" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<alias>
<typeAlias alias="UserInfo" type="Service.BO.UserInfo, Service" />
</alias>
<resultMaps>
<resultMap id="UserInfoResult" class="UserInfo">
<result property="Id" column="Id" ></result>
<result property="Name" column="Name" ></result>
<result property="Password" column="Password" ></result>
<result property="LogOnName" column="LogOnName" ></result>
<result property="Sex" column="Sex" ></result>
<result property="BirthDate" column="BirthDate" ></result>
<result property="Duty" column="Duty" ></result>
<result property="OfficialPhone" column="OfficialPhone" ></result>
<result property="Fax" column="Fax" ></result>
<result property="MobilePhone" column="MobilePhone" ></result>
<result property="Email" column="Email" ></result>
<result property="Sequence" column="Sequence" ></result>
<result property="IsDirector" column="IsDirector" ></result>
<result property="Re" column="Re" ></result>
<result property="Flag" column="Flag" ></result>
<result property="DepartmentCode" column="DepartmentCode" />
<result property ="Popedom" lazyLoad="true" select="SelectPopedomById" column="Id" ></result>
</resultMap>
</resultMaps>
<statements>
<select id="SelectUserInfo" parameterClass="string" resultMap="UserInfoResult">
select Id, Name, Password, LogOnName, Sex, BirthDate, Duty, OfficialPhone, Fax, MobilePhone, Email, Sequence, IsDirector, Re, Flag, DepartmentCode<!--, InfoCheckedNumber-->
from UserInfo
<dynamic prepend="WHERE">
<isParameterPresent>
Id = #value#
</isParameterPresent>
</dynamic>
</select>
<select id="SelectUserInfoByLoginName" parameterClass="string" resultMap="UserInfoResult">
select Id, Name, Password, LogOnName, Sex, BirthDate, Duty, OfficialPhone, Fax, MobilePhone, Email, Sequence, IsDirector, Re, Flag, DepartmentCode<!--, InfoCheckedNumber-->
from UserInfo
<dynamic prepend="WHERE">
<isParameterPresent>
LogOnName = #value#
</isParameterPresent>
</dynamic>
</select>
<select id="SelectAllUserInfo" resultMap="UserInfoResult">
select Id, Name, Password, LogOnName, Sex, BirthDate, Duty, OfficialPhone, Fax, MobilePhone, Email, Sequence, IsDirector, Re, Flag, DepartmentCode<!--, InfoCheckedNumber-->
from UserInfo
order by DepartmentCode,Sequence
</select>
<select id="SelectUserByDepCode" parameterClass="string" resultMap="UserInfoResult">
select Id, Name, Password, LogOnName, Sex, BirthDate, Duty, OfficialPhone, Fax, MobilePhone, Email, Sequence, IsDirector, Re, Flag, DepartmentCode<!--, InfoCheckedNumber-->
from UserInfo
<dynamic prepend="WHERE">
<isParameterPresent>
DepartmentCode = #value#
</isParameterPresent>
</dynamic>
order by Sequence
</select>
<select id="SelectChildUserByCode" parameterClass="string" resultMap="UserInfoResult">
select Id, Name, Password, LogOnName, Sex, BirthDate, Duty, OfficialPhone, Fax, MobilePhone, Email, Sequence, IsDirector, Re, Flag, DepartmentCode<!--, InfoCheckedNumber-->
from UserInfo
<dynamic prepend="WHERE">
<isParameterPresent>
DepartmentCode like #value#
</isParameterPresent>
</dynamic>
order by Sequence
</select>
<select id="SelectPopedomById" parameterClass="string" resultClass="Service.BO.Popedom">
select distinct Popedom.PopedomName,Popedom.Description,Popedom.Code
from Popedom, RolePopedom, RoleUser, UserInfo
where UserInfo.ID = RoleUser.UserID and RoleUser.RoleID = RolePopedom.RoleID and RolePopedom.PopedomCode = Popedom.Code and UserInfo.ID=#Id#
</select>
<insert id="InsertUserInfo" parameterClass="UserInfo">
insert into UserInfo (Id, Name, [Password], LogOnName, Sex, BirthDate, Duty, OfficialPhone, Fax, MobilePhone, Email, Sequence, IsDirector, Re, Flag, DepartmentCode)
values(#Id#, #Name#, #Password#, #LogOnName#, #Sex#, #BirthDate#, #Duty#, #OfficialPhone#, #Fax#, #MobilePhone#, #Email#, #Sequence#, #IsDirector#, #Re#, #Flag#, #DepartmentCode#)
</insert>
<update id="UpdateUserInfo" parameterClass="UserInfo">
update UserInfo set
Name = #Name#,
[Password] = #Password#,
LogOnName = #LogOnName#,
Sex = #Sex#,
BirthDate = #BirthDate#,
Duty = #Duty#,
OfficialPhone = #OfficialPhone#,
Fax = #Fax#,
MobilePhone = #MobilePhone#,
Email = #Email#,
Sequence = #Sequence#,
IsDirector = #IsDirector#,
Re = #Re#,
Flag = #Flag#,
DepartmentCode = #DepartmentCode#
where Id = #Id#
</update>
<delete id="DeleteUserInfo" parameterClass="string">
delete from UserInfo
where Id = #value#
</delete>
</statements>
</sqlMap>
UserInfo表这里面有这两者的关系.