5 Commits

Author SHA1 Message Date
kkazuya
4b537133c1 [edit] pom.xml, application.propertiesを編集 2026-09-10 16:09:48 +09:00
kkazuya
ca327d751b [edit] htmlを一部編集 2026-09-10 16:08:38 +09:00
kkazuya
e01c932413 [edit] Entity, pagepropertyを編集 2026-09-10 16:08:01 +09:00
kkazuya
b04a448ceb [edit] Contorollerを編集 2026-09-10 16:07:31 +09:00
kkazuya
e243b7e81c [edit] 部署情報検索のserviceを修正 2026-09-10 16:06:37 +09:00
12 changed files with 49 additions and 24 deletions

View File

@@ -17,6 +17,7 @@
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
<lombok.version>1.18.34</lombok.version>
</properties>
<dependencies>
<dependency>

View File

@@ -6,9 +6,7 @@ import com.example.rhizome.app.domain.model.Department;
import com.example.rhizome.app.domain.model.SearchConditionDepartment;
public interface SearchDepartment {
List<Department> searchDepartment(String nmDepartment);
List<Department> searchDepartmentById(Integer idDepartment);
Department searchDepartmentById(Integer idDepartment);
List<Department> selectAll();

View File

@@ -40,13 +40,13 @@ public class SearchDepartmentImpl implements SearchDepartment {
* @param nmDepartment 検索対象の nmDepartment
* @return Table から取得したレコードの情報
*/
public List<Department> searchDepartment(String nmDepartment) {
public List<Department> searchDepartmentByName(String nmDepartment) {
return DepartmentEntity.createDepartmentList(departmentRepository.findByNmDepartment(nmDepartment).stream().toList());
}
@Override
public List<Department> searchDepartmentById(Integer idDepartment) {
return DepartmentEntity.createDepartmentList(departmentRepository.findByIdDepartment(idDepartment).stream().toList());
public Department searchDepartmentById(Integer idDepartment) {
return DepartmentEntity.createDepartment(departmentRepository.findByIdDepartment(idDepartment).orElse(new DepartmentEntity()));
}
/**

View File

@@ -7,14 +7,21 @@
package com.example.rhizome.app.infra.entity;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.example.rhizome.app.domain.model.Department;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.util.List;
/**
* Department テーブルの Entity
*
@@ -40,6 +47,11 @@ public class DepartmentEntity {
@Column(name = "nm_department", nullable = false)
private String nmDepartment;
public static Department createDepartment(DepartmentEntity departmentEntity) {
return new Department(departmentEntity.getIdDepartment(), departmentEntity.getNmDepartment());
}
/**
* DepartmentEntity(DataAccess層依存)から Department(BusinessLogic層依存型)に変換します。
*

View File

@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import com.example.rhizome.aop.aspect.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.model.Department;
import com.example.rhizome.app.domain.model.SearchConditionDepartment;
import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.domain.service.impl.SearchDepartmentImpl;
import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
@@ -82,7 +83,7 @@ public class InsertDepartmentConfirmController {
final String DUPLICATION = "既に登録済みの部署名です。";
// 登録対象の部署名を元に検索
List<Department> departmentList = searchDepartment.searchDepartment(insertDepartmentForm.getNmDepartment());
List<Department> departmentList = searchDepartment.searchBy(new SearchConditionDepartment(null, insertDepartmentForm.getNmDepartment()));
// 検索結果があるか
if (!departmentList.isEmpty()) {

View File

@@ -52,7 +52,7 @@ class SelectDepartmentController {
*/
@PermissionCheck
@SessionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_INFO, method = RequestMethod.POST)
@RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT, method = RequestMethod.POST)
public String select(SearchConditionDepartmentForm searchConditionDepartmentForm, Model model) {
try {

View File

@@ -63,18 +63,17 @@ public class UpdateDepartmentController {
final String UPDATE_TARGET_ID_NOT_FOUND = "更新対象のデータが見つかりません。";
try {
List<Department> departmentList = searchDepartment.searchBy(
new SearchConditionDepartment(idDepartment, null)
);
List<Department> departmentList = searchDepartment.searchBy(new SearchConditionDepartment(idDepartment, null));
if (departmentList.isEmpty()) {
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(UPDATE_TARGET_ID_NOT_FOUND));
return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_INFO;
return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT;
}
model.addAttribute(PageReturnAttributeKeyword.UPDATE_DEPARTMENT_FORM, UpdateDepartmentForm.convertFrom(departmentList.get(0)));
return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML;
} catch (Exception e) {
httpSession.invalidate();

View File

@@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import com.example.rhizome.aop.aspect.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.model.Department;
import com.example.rhizome.app.domain.model.SearchConditionDepartment;
import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.domain.service.UpdateDepartment;
import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
@@ -61,7 +62,7 @@ public class UpdateDepartmentResultController {
final String UPDATE_COMPLETE = "更新が完了しました。";
try {
List<Department> departmentList = searchDepartment.searchDepartment(updateDepartmentForm.getNmDepartment());
List<Department> departmentList = searchDepartment.searchBy(new SearchConditionDepartment(null, updateDepartmentForm.getNmDepartment()));
if (!checkDuplicateNmDepartment(departmentList, updateDepartmentForm)) {
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION));
@@ -77,7 +78,7 @@ public class UpdateDepartmentResultController {
return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML;
}
Department beforeDepartment = searchDepartment.searchDepartmentById(updateDepartmentForm.getIdDepartment()).get(0);
Department beforeDepartment = searchDepartment.searchDepartmentById(updateDepartmentForm.getIdDepartment());
if (beforeDepartment.getIdDepartment() == null) {
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(NO_TARGET));
model.addAttribute(PageReturnAttributeKeyword.UPDATE_DEPARTMENT_FORM, updateDepartmentForm);

View File

@@ -50,7 +50,7 @@ public class TransitionTargetPageNameKeyword {
public static final String INSERT_DEPARTMENT = "/insertDepartment";
public static final String SHOW_MENU = "/showMenu";
public static final String SELECT_EMPLOYEE_INFO = "/selectEmployeeInfo";
public static final String SELECT_DEPARTMENT_INFO = "/selectDepartmentInfo";
public static final String SELECT_DEPARTMENT = "/selectDepartment";
public static final String SELECT_EMPLOYEE_INFO_FORM_EMPTY = "/selectAll";
public static final String SELECT_DEPARTMENT_INFO_FORM_EMPTY = "/selectAllDepartment";
public static final String SHOW_UPDATE_EMPLOYEE = "/showUpdateEmployee";
@@ -85,7 +85,7 @@ public class TransitionTargetPageNameKeyword {
INSERT_DEPARTMENT,
SHOW_MENU,
SELECT_EMPLOYEE_INFO,
SELECT_DEPARTMENT_INFO,
SELECT_DEPARTMENT,
SELECT_EMPLOYEE_INFO_FORM_EMPTY,
SELECT_DEPARTMENT_INFO_FORM_EMPTY,
SHOW_UPDATE_EMPLOYEE,

View File

@@ -1,3 +1,16 @@
spring.datasource.url=jdbc:mysql://localhost:3306/rezodb
spring.datasource.url=jdbc:mysql://localhost:3306/rezospring
spring.datasource.username=rezouser
spring.datasource.password=Rezo_0000
# SQLをログ出力
logging.level.org.hibernate.SQL=debug
# SQLのバインドパラメーターをログ出力
logging.level.org.hibernate.type=trace
logging.level.org.hibernate.orm.jdbc.bind=trace
# SELECT文の結果をログ出力
logging.level.org.hibernate.orm.jdbc.extract=trace
# SQL整形
spring.jpa.properties.hibernate.format_sql=true

View File

@@ -67,13 +67,13 @@
function selectDepartmentSubmit() {
const form = document.createElement('form');
form.setAttribute('method', 'post');
form.setAttribute('action', 'selectDepartmentInfo');
form.setAttribute('action', 'selectDepartment');
// 動的送信用のHidden
// 動的にFormを作成する場合は何かしら送信しないと、正しく動作しない
const inputField = document.createElement("input");
inputField.setAttribute("type", "hidden");
inputField.setAttribute("value", "selectDepartmentInfo");
inputField.setAttribute("value", "selectDepartment");
form.appendChild(inputField);

View File

@@ -20,7 +20,7 @@
<button class="logoutButton" onclick="logoutSubmit()">ログアウト</button>
</div>
</h1>
<form action="selectDepartmentInfo"
<form action="selectDepartment"
method="post"
th:object="${searchConditionDepartmentForm}">