Top > SAStrutsあれこれ > 住所からの従業員検索

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<html>
<head>
  <title>Tutorial: Employee Search1</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
 
<h2>Tutorial: Employee Search1</h2>
 
<s:form>
  住所キーワードを入力下さい=><html:text property="keyword" size="25" />
  <input type="submit" name="search" value="検索" />
</s:form>
 
</body>
</html>

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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<html>
<head>
<title>Tutorial: Employee List</title>
</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>Address</th>
</tr>
<c:forEach var="e" varStatus="s" items="${employees}">
<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:h(e.department.name)}</td>
<td>${f:h(e.address.name)}</td>
</tr>
</c:forEach>
</table>
</body>
</html>
Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 
 
 
 
 
-
|
|
|
|
|
!
    /**
     * 住所テーブルのname列で従業員を検索します。
     * @param keyword
     * @return
     */
    public List<Employee> findByAddress(String keyword) {
        return select()
               .innerJoin(address(), contains(address().name(), keyword))
               .innerJoin(department())
               .orderBy(asc(id()))
               .getResultList();
    }
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
SELECT
         T1_.ID AS C1_
        ,T1_.NAME AS C2_
        ,T1_.JOB_TYPE AS C3_
        ,T1_.SALARY AS C4_
        ,T1_.DEPARTMENT_ID AS C5_
        ,T1_.ADDRESS_ID AS C6_
        ,T1_.VERSION AS C7_
        ,T2_.ID AS C8_
        ,T2_.NAME AS C9_
        ,T2_.VERSION AS C10_
        ,T3_.ID AS C11_
        ,T3_.NAME AS C12_
        ,T3_.VERSION AS C13_
    FROM
        EMPLOYEE T1_ 
    INNER JOIN ADDRESS T2_
        ON T1_.ADDRESS_ID = T2_.ID AND T2_.NAME LIKE '%STREET 4%' 
    INNER JOIN DEPARTMENT T3_
        ON T1_.DEPARTMENT_ID = T3_.ID
ORDER BY
    C1_
Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 
 
 
 
 
 
-
|
|
|
|
|
|
|
-
|
!
!
package tutorial.form;
 
import java.util.List;
import tutorial.entity.Department;
import tutorial.entity.Employee;
 
public class Search1Form {
    
    public String keyword;
    
    public List<Employee> employees;
    
    public List<Department> departments;
    
    public void initialize() {
        keyword = "STREET 1";
    }
}
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
 
 
 
 
 
 
 
 
 
 
 
 
-
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
!
|
|
-
|
|
|
!
!
 
package tutorial.action;
 
import javax.annotation.Resource;
import org.seasar.extension.jdbc.SqlLog;
import org.seasar.extension.jdbc.SqlLogRegistry;
import org.seasar.extension.jdbc.SqlLogRegistryLocator;
import org.seasar.struts.annotation.ActionForm;
import org.seasar.struts.annotation.Execute;
import tutorial.form.Search1Form;
import tutorial.service.DepartmentService;
import tutorial.service.EmployeeService;
 
public class Search1Action {
  
    @ActionForm
    @Resource
    protected Search1Form search1Form;
    
    @Resource
    protected EmployeeService employeeService;
    
    @Resource
    protected DepartmentService departmentService;
    
    @Execute(validator = false)
    public String index() {
        search1Form.initialize();
        return "index.jsp";
    }
    
    @Execute(validator = false)
    public String search() {
        search1Form.employees = employeeService.findByAddress(search1Form.keyword);
        search1Form.departments = departmentService.findAll();
        return "result.jsp";
    }
}

添付ファイル: filet_safe_search1_2.jpg 453件 [詳細] filet_safe_search1_1.jpg 471件 [詳細]

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