Top > SAStrutsあれこれ > 従業員情報のリストをXMLで返してみましょう
Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 
 
 
-
|
|
|
|
!
import tutorial.dto.Employees;
===================================
    @Execute(validator = false)
    public String index3() throws IOException, JAXBException {
        Employees employees = new Employees();
        employees.employeeList = employeeService.findAll();
        sendXML(Employees.class, employees);
        return null;
    }

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 
 
 
 
 
 
 
 
-
|
|
|
!
package tutorial.dto;
 
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import tutorial.entity.Employee;
 
@XmlRootElement(name="Employees")
public class Employees {
    
    @XmlElement(name="Employee")
    public List<Employee> employeeList;
}
Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 
 
 
 
 
 
-
|
|
|
|
|
!
    /**
     * 従業員情報を全件取得します。
     * 住所情報と部署情報も結合して取得します。
     * @return
     */
    @Override
    public List<Employee> findAll() {
        return select()
               .innerJoin(address())
               .innerJoin(department())
               .orderBy(asc(id()))
               .getResultList();
    }
Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
 
 
-
|
|
|
|
|
@Entity
@XmlRootElement(name="Department")
public class Department {
=========================================
    /** employeeList関連プロパティ */
    @OneToMany(mappedBy = "department")
    @XmlTransient
    public List<Employee> employeeList;
Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
 
 
-
|
|
|
|
|
@Entity
@XmlRootElement(name="Address")
public class Address {
=========================================
    /** employeeList関連プロパティ */
    @OneToMany(mappedBy = "address")
    @XmlTransient
    public List<Employee> employeeList;
Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Employees>
    <Employee>
        <id>1</id>
        <name>ALLEN</name>
        <jobType>SALESMAN</jobType>
        <salary>1600</salary>
        <departmentId>3</departmentId>
        <addressId>1</addressId>
        <address>
            <id>1</id>
            <name>STREET 1</name>
            <version>1</version>
        </address>
        <department>
            <id>3</id>
            <name>SALES</name>
            <version>1</version>
        </department>
    </Employee>
    <Employee>
        <id>2</id>
        <name>WARD</name>
        <jobType>SALESMAN</jobType>
        <salary>1250</salary>
        <departmentId>3</departmentId>
        <addressId>2</addressId>
        <address>
            <id>2</id>
            <name>STREET 2</name>
            <version>1</version>
        </address>
        <department>
            <id>3</id>
            <name>SALES</name>
            <version>1</version>
        </department>
    </Employee>
    <Employee>
        <id>3</id>
        <name>JONES</name>
        <jobType>MANAGER</jobType>
        <salary>2975</salary>
        <departmentId>2</departmentId>
        <addressId>3</addressId>
        <address>
            <id>3</id>
            <name>STREET 3</name>
            <version>1</version>
        </address>
        <department>
            <id>2</id>
            <name>RESEARCH</name>
            <version>1</version>
        </department>
    </Employee>
    <Employee>
        <id>4</id>
        <name>MARTIN</name>
        <jobType>SALESMAN</jobType>
        <salary>1250</salary>
        <departmentId>3</departmentId>
        <addressId>4</addressId>
        <address>
            <id>4</id>
            <name>STREET 4</name>
            <version>1</version>
        </address>
        <department>
            <id>3</id>
            <name>SALES</name>
            <version>1</version>
        </department>
    </Employee>
    <Employee>
        <id>5</id>
        <name>BLAKE</name>
        <jobType>MANAGER</jobType>
        <salary>2850</salary>
        <departmentId>3</departmentId>
        <addressId>5</addressId>
        <address>
            <id>5</id>
            <name>STREET 5</name>
            <version>1</version>
        </address>
        <department>
            <id>3</id>
            <name>SALES</name>
            <version>1</version>
        </department>
    </Employee>
    <Employee>
        <id>6</id>
        <name>CLARK</name>
        <jobType>MANAGER</jobType>
        <salary>2450</salary>
        <departmentId>1</departmentId>
        <addressId>6</addressId>
        <address>
            <id>6</id>
            <name>STREET 6</name>
            <version>1</version>
        </address>
        <department>
            <id>1</id>
            <name>ACCOUNTING</name>
            <version>1</version>
        </department>
    </Employee>
    <Employee>
        <id>7</id>
        <name>SCOTT</name>
        <jobType>ANALYST</jobType>
        <salary>3000</salary>
        <departmentId>2</departmentId>
        <addressId>7</addressId>
        <address>
            <id>7</id>
            <name>STREET 7</name>
            <version>1</version>
        </address>
        <department>
            <id>2</id>
            <name>RESEARCH</name>
            <version>1</version>
        </department>
    </Employee>
    <Employee>
        <id>8</id>
        <name>KING</name>
        <jobType>PRESIDENT</jobType>
        <salary>5000</salary>
        <departmentId>1</departmentId>
        <addressId>8</addressId>
        <address>
            <id>8</id>
            <name>STREET 8</name>
            <version>1</version>
        </address>
        <department>
            <id>1</id>
            <name>ACCOUNTING</name>
            <version>1</version>
        </department>
    </Employee>
    <Employee>
        <id>9</id>
        <name>TURNER</name>
        <jobType>SALESMAN</jobType>
        <salary>1500</salary>
        <departmentId>3</departmentId>
        <addressId>9</addressId>
        <address>
            <id>9</id>
            <name>STREET 9</name>
            <version>1</version>
        </address>
        <department>
            <id>3</id>
            <name>SALES</name>
            <version>1</version>
        </department>
    </Employee>
    <Employee>
        <id>10</id>
        <name>ADAMS</name>
        <jobType>CLERK</jobType>
        <salary>1100</salary>
        <departmentId>2</departmentId>
        <addressId>10</addressId>
        <address>
            <id>10</id>
            <name>STREET 10</name>
            <version>1</version>
        </address>
        <department>
            <id>2</id>
            <name>RESEARCH</name>
            <version>1</version>
        </department>
    </Employee>
    <Employee>
        <id>11</id>
        <name>JAMES</name>
        <jobType>CLERK</jobType>
        <salary>950</salary>
        <departmentId>3</departmentId>
        <addressId>11</addressId>
        <address>
            <id>11</id>
            <name>STREET 11</name>
            <version>1</version>
        </address>
        <department>
            <id>3</id>
            <name>SALES</name>
            <version>1</version>
        </department>
    </Employee>
    <Employee>
        <id>12</id>
        <name>FORD</name>
        <jobType>ANALYST</jobType>
        <salary>3000</salary>
        <departmentId>2</departmentId>
        <addressId>12</addressId>
        <address>
            <id>12</id>
            <name>STREET 12</name>
            <version>1</version>
        </address>
        <department>
            <id>2</id>
            <name>RESEARCH</name>
            <version>1</version>
        </department>
    </Employee>
    <Employee>
        <id>13</id>
        <name>MILLER</name>
        <jobType>CLERK</jobType>
        <salary>1300</salary>
        <departmentId>1</departmentId>
        <addressId>13</addressId>
        <address>
            <id>13</id>
            <name>STREET 13</name>
            <version>1</version>
        </address>
        <department>
            <id>1</id>
            <name>ACCOUNTING</name>
            <version>1</version>
        </department>
    </Employee>
    <Employee>
        <id>14</id>
        <name>SMITH</name>
        <jobType>CLERK</jobType>
        <salary>800</salary>
        <departmentId>2</departmentId>
        <addressId>14</addressId>
        <address>
            <id>14</id>
            <name>STREET 14</name>
            <version>1</version>
        </address>
        <department>
            <id>2</id>
            <name>RESEARCH</name>
            <version>1</version>
        </department>
    </Employee>
</Employees>

リロード   新規 編集 凍結解除 差分 添付 複製 名前変更   ホーム 一覧 単語検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS
Last-modified: 2012-08-08 (水) 23:26:17 (2925d)