Compare commits
6 Commits
e36345e980
...
k-kobayash
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
518c197970 | ||
|
|
4b537133c1 | ||
|
|
ca327d751b | ||
|
|
e01c932413 | ||
|
|
b04a448ceb | ||
|
|
e243b7e81c |
1
pom.xml
1
pom.xml
@@ -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>
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
*
|
||||
@@ -39,7 +46,12 @@ 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層依存型)に変換します。
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
@@ -64,6 +65,7 @@ public class InsertDepartmentConfirmController {
|
||||
public String insertDepartmentConfirm(InsertDepartmentForm insertDepartmentForm, Model model) {
|
||||
|
||||
try {
|
||||
insertDepartmentForm.setNmDepartment(insertDepartmentForm.getNmDepartment().strip());
|
||||
|
||||
// 登録用パラメータチェック
|
||||
List<String> error = insertDepartmentForm.validateParameter();
|
||||
@@ -82,7 +84,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()) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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,8 @@ public class UpdateDepartmentResultController {
|
||||
final String UPDATE_COMPLETE = "更新が完了しました。";
|
||||
|
||||
try {
|
||||
List<Department> departmentList = searchDepartment.searchDepartment(updateDepartmentForm.getNmDepartment());
|
||||
updateDepartmentForm.setNmDepartment(updateDepartmentForm.getNmDepartment().strip());
|
||||
List<Department> departmentList = searchDepartment.searchBy(new SearchConditionDepartment(null, updateDepartmentForm.getNmDepartment()));
|
||||
|
||||
if (!checkDuplicateNmDepartment(departmentList, updateDepartmentForm)) {
|
||||
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION));
|
||||
@@ -77,7 +79,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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -31,7 +31,7 @@ public class UpdateDepartmentForm {
|
||||
public static Department counvertTo(UpdateDepartmentForm updateDepartmentForm) {
|
||||
return new Department(
|
||||
updateDepartmentForm.getIdDepartment(),
|
||||
updateDepartmentForm.getNmDepartment()
|
||||
updateDepartmentForm.getNmDepartment()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<button class="logoutButton" onclick="logoutSubmit()">ログアウト</button>
|
||||
</div>
|
||||
</h1>
|
||||
<form action="selectDepartmentInfo"
|
||||
<form action="selectDepartment"
|
||||
method="post"
|
||||
th:object="${searchConditionDepartmentForm}">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user