Top > SAStrutsあれこれ > 「データベースを使ったサンプル」を軽く改造(1)

Everything is expanded.Everything is shortened.
  1
 
.innerJoin("department")

   /**
    * 部署です。
    */
   @ManyToOne
   public Department department;

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 
 
 
 
-
-
|
!
!
package tutorial.service;
import java.util.List;
import tutorial.entity.Employee;
 
public class EmployeeService extends AbstractService<Employee> {
    public List<Employee> findAllWithDept() {
        return select().innerJoin("department").orderBy("id").getResultList();
    }
}
Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
 
-
|
|
|
!
    @Execute(validator = false)
    public String index() {
        empItems = employeeService.findAll();
        deptItems = departmentService.findAll();
        return "index.jsp";
    }

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
 
-
|
|
|
|
!
    @Execute(validator = false)
    public String index() {
        //empItems = employeeService.findAll();
        //deptItems = departmentService.findAll();
        empItems = employeeService.findAllWithDept();
        return "index.jsp";
    }
Everything is expanded.Everything is shortened.
  1
 
<td>${f:h(e.department.name)}</td>

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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<%@page pageEncoding="UTF-8" %>
<html>
<head>
<title>Tutorial: Employee List</title>
<link rel="stylesheet" type="text/css" href="${f:url('/css/sa.css')}" />
 
</head>
<body>
<h1>Tutorial: Employee List</h1>
 
<table border="1">
<tr style="background-color:pink">
<th>Id</th><th>Name</th><th>JobType</th><th>Salary</th><th>Department</th><th>編集</th>
</tr>
<c:forEach var="e" varStatus="s" items="${empItems}">
<tr style="background-color:${s.index %2 == 0 ? 'white' : 'yellow'}">
<td align="right">${f:h(e.id)}</td>
<td>${f:h(e.name)}</td>
<td>${f:h(e.jobType)}</td>
<td align="right"><fmt:formatNumber value="${e.salary}" pattern="#,##0"/></td>
<%-- <td>${f:label(e.departmentId, deptItems, "id", "name")}</td> --%>
<td>${f:h(e.department.name)}</td>
<td><s:link href="edit/${f:u(e.id)}">編集</s:link></td>
</tr>
</c:forEach>
</table>
 
</body>
</html>

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
-
|
|
|
|
|
|
!
public class Employee {
    ...
    public Integer departementId;
    
    @ManyToOne
    @JoinColumn(name="DEPARTMENT_ID", referencedColumnName="id")
    public Department department;
}

添付ファイル: fileemployee_hsqldb1.jpg 464件 [詳細]

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