社員情報登録時のプルダウンの分割化の相談の参照用の一時プッシュ追加分

This commit is contained in:
o-yamamoto
2026-09-28 14:26:46 +09:00
parent 995fe03b73
commit 820d030602
2 changed files with 147 additions and 139 deletions

View File

@@ -2,6 +2,7 @@ package com.example.rhizome.app.presentation.controller;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.*; import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.*;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -10,9 +11,12 @@ import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.example.rhizome.aop.aspect.PermissionCheck; import com.example.rhizome.aop.aspect.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck; import com.example.rhizome.aop.aspect.SessionCheck;
@@ -20,7 +24,9 @@ import com.example.rhizome.app.domain.service.RegisterEmployee;
import com.example.rhizome.app.domain.service.SearchDepartment; import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword; import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword; import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.DepartmentForm; import com.example.rhizome.app.presentation.form.DepartmentInfoForm;
import com.example.rhizome.app.presentation.form.DivisionInfoForm;
import com.example.rhizome.app.presentation.form.HeadquartersInfoForm;
import com.example.rhizome.app.presentation.form.InsertEmployeeForm; import com.example.rhizome.app.presentation.form.InsertEmployeeForm;
/** /**
@@ -51,44 +57,14 @@ public class InsertEmployeeInputController {
return new InsertEmployeeForm(); return new InsertEmployeeForm();
} }
//プルダウン絞り込み無し実装用
/** // /**
* 登録画面表示処理 // * 登録画面表示処理
* // *
* @param insertEmployeeForm 登録画面のフォーム // * @param insertEmployeeForm 登録画面のフォーム
* @param model ビューにデータを渡すためのコンテナ // * @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面 // * @return 遷移先の画面
*/ // */
@SessionCheck
@PermissionCheck
@RequestMapping(value = INSERT_EMPLOYEE_INPUT, method = RequestMethod.POST)
public String insertInput(InsertEmployeeForm insertEmployeeForm, Model model) {
try {
// 部署コードリストを作成し、画面に返す値としてセット
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST
,DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable()));
// パラメータをセット
model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm);
// 登録画面に遷移
return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML;
} catch (Exception e) {
// ログイン情報の破棄
httpSession.invalidate();
e.printStackTrace();
// エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// エラー画面遷移
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
//プルダウン絞り込み実装用
// @SessionCheck // @SessionCheck
// @PermissionCheck // @PermissionCheck
// @RequestMapping(value = INSERT_EMPLOYEE_INPUT, method = RequestMethod.POST) // @RequestMapping(value = INSERT_EMPLOYEE_INPUT, method = RequestMethod.POST)
@@ -97,7 +73,7 @@ public class InsertEmployeeInputController {
// try { // try {
// // 部署コードリストを作成し、画面に返す値としてセット // // 部署コードリストを作成し、画面に返す値としてセット
// model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST // model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST
// ,HeadquartersInfoForm.convertFrom( // ,DepartmentForm.convertFrom(
// searchDepartment.searchAllDepartmentTable())); // searchDepartment.searchAllDepartmentTable()));
// //
// // パラメータをセット // // パラメータをセット
@@ -118,45 +94,75 @@ public class InsertEmployeeInputController {
// return TransitionTargetPageNameKeyword.ERROR_HTML; // return TransitionTargetPageNameKeyword.ERROR_HTML;
// } // }
// } // }
//プルダウン絞り込み実装用
@SessionCheck
@PermissionCheck
@RequestMapping(value = INSERT_EMPLOYEE_INPUT, method = RequestMethod.POST)
public String insertInput(InsertEmployeeForm insertEmployeeForm, Model model) {
// @GetMapping("insertEmployeeInput/searchDepartment" ) try {
// @ResponseBody // 部署コードリストを作成し、画面に返す値としてセット
// public List<DepartmentInfoForm>departmentsByHeadquarters( model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST
// @RequestParam("id_headquarters")Integer idHeadquarters){ ,HeadquartersInfoForm.convertFrom(
// System.out.println("koko"); searchDepartment.searchAllDepartmentTable()));
//
// List<DepartmentInfoForm> departmentByHeadquarters= // パラメータをセット
// DepartmentInfoForm.convertFrom( model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm);
// searchDepartment.searchByIdHeadquarters(idHeadquarters));
// System.out.println("2"); // 登録画面に遷移
// return departmentByHeadquarters return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML;
// .stream()
// .map(DepartmentInfoForm-> new DepartmentInfoForm( } catch (Exception e) {
// DepartmentInfoForm.getIdDepartment(), // ログイン情報の破棄
// DepartmentInfoForm.getNmDepartment())) httpSession.invalidate();
// .distinct()
// .toList(); e.printStackTrace();
//
// // エラーログ出力
// } LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// @GetMapping("/insertEmployeeInput/searchDepartment/searchDivision") // エラー画面遷移
// @ResponseBody return TransitionTargetPageNameKeyword.ERROR_HTML;
// public List<DivisionInfoForm>divisionBydepartment( }
// @RequestParam("idDepartment")Integer idDepartment){ }
// List<DivisionInfoForm> divisionBydepartment=
// DivisionInfoForm.convertFrom( @GetMapping("insertEmployeeInput/searchDepartment" )
// searchDepartment.searchByIdDepartment(idDepartment)); @ResponseBody
// public List<DepartmentInfoForm>departmentsByHeadquarters(
// return divisionBydepartment @RequestParam("id_headquarters")Integer idHeadquarters){
// .stream() System.out.println("koko");
// .map(DivisionInfoForm-> new DivisionInfoForm(
// DivisionInfoForm.getIdDivision(), List<DepartmentInfoForm> departmentByHeadquarters=
// DivisionInfoForm.getNmDivision())) DepartmentInfoForm.convertFrom(
// .distinct() searchDepartment.searchByIdHeadquarters(idHeadquarters));
// .toList(); System.out.println("2");
// return departmentByHeadquarters
// .stream()
// } .map(DepartmentInfoForm-> new DepartmentInfoForm(
DepartmentInfoForm.getIdDepartment(),
DepartmentInfoForm.getNmDepartment()))
.distinct()
.toList();
}
@GetMapping("/insertEmployeeInput/searchDepartment/searchDivision")
@ResponseBody
public List<DivisionInfoForm>divisionBydepartment(
@RequestParam("idDepartment")Integer idDepartment){
List<DivisionInfoForm> divisionBydepartment=
DivisionInfoForm.convertFrom(
searchDepartment.searchByIdDepartment(idDepartment));
return divisionBydepartment
.stream()
.map(DivisionInfoForm-> new DivisionInfoForm(
DivisionInfoForm.getIdDivision(),
DivisionInfoForm.getNmDivision()))
.distinct()
.toList();
}
} }

View File

@@ -167,43 +167,45 @@
<th class="header" >所属部</th> <th class="header" >所属部</th>
<td> <td>
<!-- プルダウン絞り込み実装用--> <!-- プルダウン絞り込み実装用-->
<!-- <label>--> <label>
<!-- <select id="departmentSelect" required="required" th:field="*{idDepartment}"> --> <select id="departmentSelect" required="required" th:field="*{idDepartment}">
<!-- <option value="">先に本部を選択してください</option>--> <option value="">先に本部を選択してください</option>
<!-- </select>--> </select>
<!-- </label>--> </label>
<label> <!-- プルダウン絞り込み無し実装用-->
<select id="departmentSelect" required="required" th:field="*{idDepartment}"> <!-- <label>-->
<!-- <select id="departmentSelect" required="required" th:field="*{idDepartment}">-->
<option th:each="department : ${departmentFormList}" <!-- <option th:each="department : ${departmentFormList}"-->
th:utext=" <!-- th:utext="-->
${department.nmDepartment}" <!-- ${department.nmDepartment}"-->
th:value="${department.idDepartment}"> <!-- th:value="${department.idDepartment}">-->
</option> <!-- </option>-->
</select> <!-- </select>-->
</label> <!-- </label>-->
</td> </td>
</tr> </tr>
<tr> <tr>
<th class="header" >所属課</th> <th class="header" >所属課</th>
<td> <td>
<label> <!-- プルダウン絞り込み無し実装用-->
<select id="divisionSelect" required="required" th:field="*{idDivision}"> <!-- <label>-->
<option th:each="division : ${departmentFormList}" <!-- <select id="divisionSelect" required="required" th:field="*{idDivision}">-->
th:utext=" <!-- <option th:each="division : ${departmentFormList}"-->
${division.nmDivision}" <!-- th:utext="-->
th:value="${division.idDivision}"> <!-- ${division.nmDivision}"-->
</option> <!-- th:value="${division.idDivision}">-->
</select> <!-- </option>-->
</label> <!-- </select>-->
<!-- </label>-->
<!-- プルダウン絞り込み実装用--> <!-- プルダウン絞り込み実装用-->
<!-- <label>--> <label>
<!-- <select id="divisionSelect" required="required" th:field="*{idDivision}">--> <select id="divisionSelect" required="required" th:field="*{idDivision}">
<!-- <option value="">先に部を選択してください</option>--> <option value="">先に部を選択してください</option>
<!-- </select>--> </select>
<!-- </label>--> </label>
</td> </td>
</tr> </tr>
@@ -217,46 +219,46 @@
<a href="showMenu">メニューに戻る</a> <a href="showMenu">メニューに戻る</a>
</body> </body>
<!--プルダウン絞り込み実装用(途中)--> <!--プルダウン絞り込み実装用(途中)-->
<!--<script>--> <script>
<!--const headquartersSelect = document.getElementById('headquartersSelect');--> const headquartersSelect = document.getElementById('headquartersSelect');
<!--const departmentSelect = document.getElementById('departmentSelect');--> const departmentSelect = document.getElementById('departmentSelect');
<!--const divisionSelect = document.getElementById('divisionSelect');--> const divisionSelect = document.getElementById('divisionSelect');
<!--headquartersSelect.addEventListener('change', function() {--> headquartersSelect.addEventListener('change', function() {
<!-- const id_headquarters = this.value; --> const id_headquarters = this.value;
<!-- departmentSelect.disabled = true;--> departmentSelect.disabled = true;
<!-- divisionSelect.disabled = true;--> divisionSelect.disabled = true;
<!-- departmentSelect.innerHTML = '<option value="">-- 部を選択 --</option>';--> departmentSelect.innerHTML = '<option value="">-- 部を選択 --</option>';
<!-- divisionSelect.innerHTML = '<option value="">-- 先に部を選択してください --</option>';--> divisionSelect.innerHTML = '<option value="">-- 先に部を選択してください --</option>';
<!-- console.log("koko");--> console.log("koko");
<!-- if (!id_headquarters) return;--> if (!id_headquarters) return;
<!-- fetch(`insertEmployeeInput/searchDepartment?id_headquarters=${id_headquarters}`,{ --> fetch(`insertEmployeeInput/searchDepartment?id_headquarters=${id_headquarters}`,{
<!-- method: 'GET',--> method: 'GET',
<!-- headers: {--> headers: {
<!-- 'Accept': 'application/json' --> 'Accept': 'application/json'
<!-- }--> }
<!-- })--> })
<!-- .then(res => {--> .then(res => {
<!-- console.log("koko");--> console.log("koko");
<!-- return res.json();--> return res.json();
<!-- })--> })
<!-- .then(list => {--> .then(list => {
<!-- departmentSelect.disabled = false; --> departmentSelect.disabled = false;
<!-- list.forEach(form => {--> list.forEach(form => {
<!-- const opt = document.createElement('option');--> const opt = document.createElement('option');
<!-- opt.value = form.idDepartment; --> opt.value = form.idDepartment;
<!-- opt.textContent = form.nmDepartment; --> opt.textContent = form.nmDepartment;
<!-- departmentSelect.appendChild(opt);--> departmentSelect.appendChild(opt);
<!-- });--> });
<!-- })--> })
<!--});--> });
<!--</script>--> </script>
</html> </html>