ibatis和java中如何处理多个表的sql映射

发布于 2024-10-06 08:41:35 字数 542 浏览 2 评论 0原文

我正在尝试将 Ibatis 与 GWT 结合使用,我有这样的场景,我有数据库表机场、航站楼和航班。一个机场可以有不同的航站楼。一个航站楼可以有一个机场和多个航班。一个航班可以有一个航站楼。所以表结构看起来像这样。

飞机场 -ID -姓名 -terminal_id

终端 -ID -姓名 -flight_id

航班 -ID -航空公司 -terminal_id

我的 select 语句如下所示

SELECT airport.name AS Airport,
       terminals.name AS Terminal,
       flights.airline,
FROM airport,
     terminals,
     flights
WHERE airport.terminal_id = terminals.id
  AND terminals.flight_id = flights.id;

获得此结果的 sql 映射将是什么样子。我感到困惑的是结果集是表的组合,因此结果集不是三个表中任何一个的模型对象。

I am trying to use Ibatis with GWT and I have this scenario, I have databases tables Airport, Terminals and Flights. An airport can have different terminals. A terminal can have one Airport and many flights. And a flight can have one terminal. So the table structure looks like this.

Airport
-id
-name
-terminal_id

Terminals
-id
-name
-flight_id

Flights
-id
-airline
-terminal_id

My select statement looks like this

SELECT airport.name AS Airport,
       terminals.name AS Terminal,
       flights.airline,
FROM airport,
     terminals,
     flights
WHERE airport.terminal_id = terminals.id
  AND terminals.flight_id = flights.id;

What will the sql maps look like to get this result. Where I'm getting confused is the result set is a combination of tables and so the result set isn't a model object of either of the three tables.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

计㈡愣 2024-10-13 08:41:35

创建一个自定义值对象(vo)以满足您的需要。

<sqlMap namespace="Arrival">
<resultMap id="Arrival" class="com.flight.vo.Arrival">
    <result property="airport" column="Airport" />
    <result property="terminal" column="Terminal" />
    <result property="airline" column="airline"/>
</resultMap>

<select id="retrieveAllArrivals" resultMap="Arrival.Arrival" >
    select airport.name as Airport, terminals.name as Terminal, flights.airline
    FROM airport, terminals, flights 
    WHERE airport.terminal_id = terminals.id 
    AND terminals.flight_id = flights.id
</select>
</sqlMap>

Create a custom value object(vo) to suit your need.

<sqlMap namespace="Arrival">
<resultMap id="Arrival" class="com.flight.vo.Arrival">
    <result property="airport" column="Airport" />
    <result property="terminal" column="Terminal" />
    <result property="airline" column="airline"/>
</resultMap>

<select id="retrieveAllArrivals" resultMap="Arrival.Arrival" >
    select airport.name as Airport, terminals.name as Terminal, flights.airline
    FROM airport, terminals, flights 
    WHERE airport.terminal_id = terminals.id 
    AND terminals.flight_id = flights.id
</select>
</sqlMap>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文