spring,springmvc,mybatits集成实例--多表关联查询 雨点打透心脏的1/2处 2022-06-09 12:45 153阅读 0赞 # spring,springmvc,mybatits集成实例–多表关联查询 # ![这里写图片描述][SouthEast] 相比于ssh,ssm框架更加简洁,轻巧,并且sql语句和代码耦合更低。本文给出一个ssm集成多表查询的实例 完整代码下载链接: [http://download.csdn.net/download/yhhyhhyhhyhh/9965943][http_download.csdn.net_download_yhhyhhyhhyhh_9965943] **环境** > eclipse4.7.0,jdk1.8,maven,spring4.3.0,mybatis3.2.5,mysql。 ## <table> <tbody> <tr> <td>1.配置</td> </tr> </tbody> </table> ## #### <table> <tbody> <tr> <td>1.1数据准备</td> </tr> </tbody> </table> #### (1)建库:`create database hms` (2)本实例有3个数据表:department,employeer,onbusiness,**代码中包含3个表的sql文件,可以直接导入使用。** ![这里写图片描述][SouthEast 1] #### <table> <tbody> <tr> <td>1.2generatorConfig工具自动生成model,mapper.xml,dao</td> </tr> </tbody> </table> #### #### <table> <tbody> <tr> <td>1.3工程配置</td> </tr> </tbody> </table> #### #### 1.2及1.3相关配置见上文:[spring,springmvc,mybatis集成实例–增删查改][spring_springmvc_mybatis]或者下载完整代码工程: #### #### <table> <tbody> <tr> <td>1.4多表关联查询相关配置</td> </tr> </tbody> </table> #### 以一对多为例,进行多表查询。 (1)在自动构建实体,map文件的基础上,在一对多的一(实体中)添加成员变量, ![这里写图片描述][SouthEast 2] (2)在实体mapper文件中添加相应的关联查询接口 ![这里写图片描述][SouthEast 3] (3)在mapper.xml中定义关联查询的结果映射集,resultMap ![这里写图片描述][SouthEast 4] (4)根据(2)中定义的接口,编写查询语句 ![这里写图片描述][SouthEast 5] \#\# <table> <tbody> <tr> <td>2.测试</td> </tr> </tbody> </table> #### <table> <tbody> <tr> <td>2.1工程</td> </tr> </tbody> </table> #### **工程目录,分三层。** ![这里写图片描述][SouthEast 6] #### <table> <tbody> <tr> <td>2.2简单测试</td> </tr> </tbody> </table> #### 关联查询测试: ![这里写图片描述][SouthEast 7] **部门表对员工表:** ![这里写图片描述][SouthEast 8] **员工表对出差单表:** ![这里写图片描述][SouthEast 9] [SouthEast]: /images/20220609/88de9f3a842e48e0b053d5f8702fc7ef.png [http_download.csdn.net_download_yhhyhhyhhyhh_9965943]: http://download.csdn.net/download/yhhyhhyhhyhh/9965943 [SouthEast 1]: /images/20220609/b3c3a78920fd4f98bfb3733ac2f0b639.png [spring_springmvc_mybatis]: http://blog.csdn.net/yhhyhhyhhyhh/article/details/77854450 [SouthEast 2]: /images/20220609/93d60e91ffc74b95ae914ae17676f7bd.png [SouthEast 3]: /images/20220609/f48f50a7c1d84c5883f113ba39cf1269.png [SouthEast 4]: /images/20220609/98488fd1ad45422aa61d7f7ff2f19759.png [SouthEast 5]: /images/20220609/78b80b4170fb4ba3afc8709aa34813e6.png [SouthEast 6]: /images/20220609/93e4e371a0364104987e951800d9b9b6.png [SouthEast 7]: /images/20220609/586893ea3e8c4033a6c5a280a6d4c7b7.png [SouthEast 8]: /images/20220609/87957a1b65c4443086d7f3044c5a57aa.png [SouthEast 9]: /images/20220609/2c2ddab0c7054d489550dc803f980d6b.png
还没有评论,来说两句吧...