爱站网关键字挖掘,江西九江网站建设,小牛加速器,做网站建设怎么样创建自定义映射规则
select idselectArtist resultMaptestselect * from artist
/select
在SQL语句标签中将resultType修改为resultMap#xff0c;即自定义映射的id。
编写自定义映射规则#xff1a;
resultMap idtes…
创建自定义映射规则
select idselectArtist resultMaptestselect * from artist
/select
在SQL语句标签中将resultType修改为resultMap即自定义映射的id。
编写自定义映射规则
resultMap idtest typecom.test.artist
result columnaID propertyaID_java/
/resultMapresultMap标签:id用以连接select标签type代替了select标签中的resultType属性。
result标签:column代表数据库中的字段名property代表赋值给的实体类成员变量名。 实现多表查询
1.一对多查询
Data
public class Teacher {int tid;String name;ListStudent studentList;
}select idgetTeacherByTid resultMapasTeacher
select *, teacher.name as tname from student
inner join teach on student.sid teach.sid
inner join teacher on teach.tid teacher.tid where teach.tid #{tid}
/selectresultMap idasTeacher typeTeacherid columntid propertytid/result columntname propertyname/collection propertystudentList ofTypeStudentid propertysid columnsid/result columnname propertyname/result columnsex propertysex//collection
/resultMapresult.id:表示自定义映射的唯一标识不能重复。
collection标签:property表示集合的成员变量名称ofType表示集合数据泛型为一个类。
在collection标签中继续写子查询结果列表。
2.多对一查询
resultMap idtest2 typeStudentid columnsid propertysid/result columnname propertyname/result columnsex propertysex/association propertyteacher javaTypeTeacherid columntid propertytid/result columntname propertyname//association
/resultMap
select idselectStudent resultMaptest2select *, teacher.name as tname from student left join teach on student.sid teach.sidleft join teacher on teach.tid teacher.tid
/selectassociation标签:property表示实体类的成员变量名称ofType表示变量类型为一个类。
在association标签中继续写子查询结果列表。