Compare commits
2 Commits
t-eguchi
...
f9456bf9e7
| Author | SHA1 | Date | |
|---|---|---|---|
| f9456bf9e7 | |||
| 17c0ec0bcd |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/.metadata/
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package com.example.demo;
|
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
|
||||||
|
|
||||||
import com.example.demo.presentation.Q2View;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
|
||||||
public class Application {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
|
|
||||||
Q2View sample = context.getBean(Q2View.class);
|
|
||||||
sample.view();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.example.demo;
|
|
||||||
|
|
||||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
|
||||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
|
||||||
|
|
||||||
public class ServletInitializer extends SpringBootServletInitializer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
|
||||||
return application.sources(Application.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package com.example.demo.application;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Q2Entity;
|
|
||||||
import com.example.demo.logic.Q2Logic;
|
|
||||||
import com.example.demo.service.Q2Service;
|
|
||||||
|
|
||||||
public class Q2Controller {
|
|
||||||
|
|
||||||
private Q2Service service;
|
|
||||||
|
|
||||||
private Q2Logic logic;
|
|
||||||
|
|
||||||
public Q2Controller(Q2Service service, Q2Logic logic) {
|
|
||||||
this.service = service;
|
|
||||||
this.logic = logic;
|
|
||||||
}
|
|
||||||
public String show(String mailAddress, String password) {
|
|
||||||
if (mailAddress.length() > 256) {
|
|
||||||
return "メールアドレスもしくはパスワードが不正です";
|
|
||||||
}
|
|
||||||
if (password.length() < 8) {
|
|
||||||
return "メールアドレスもしくはパスワードが不正です";
|
|
||||||
}
|
|
||||||
// サービスクラスのメソッド実行
|
|
||||||
Q2Entity entityresult = service.handleUserData(mailAddress, password);
|
|
||||||
// サービスの戻り値をロジックに渡し、その戻り値をViewに返却
|
|
||||||
String result = logic.generateMessage(entityresult);
|
|
||||||
return result;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.example.demo.logic;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Q2Entity;
|
|
||||||
|
|
||||||
public class Q2Logic {
|
|
||||||
// 引数を受け取り、指定の形式で文字列を作成して返却
|
|
||||||
public String generateMessage(Q2Entity entity) {
|
|
||||||
// 変更方式
|
|
||||||
String result = "メールアドレス:" + entity.getMailAddress() + "パスワード:" + entity.getPassword();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.example.demo.persistence;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Q2Entity;
|
|
||||||
|
|
||||||
public class Q2Dao {
|
|
||||||
// 引数を受け取り、Entityに格納して返却するメソッド
|
|
||||||
public Q2Entity createEntity(String mailAddress, String password) {
|
|
||||||
// 2.受け取った引数(メールアドレスとパスワード)をエンティティクラス型のインスタンスに格納
|
|
||||||
Q2Entity entity = new Q2Entity(mailAddress, password);
|
|
||||||
// 格納したインスタンスをサービスクラスに戻り値として返却
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package com.example.demo.presentation;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
import com.example.demo.application.Q2Controller;
|
|
||||||
|
|
||||||
public class Q2View {
|
|
||||||
|
|
||||||
private Q2Controller cont;
|
|
||||||
|
|
||||||
public Q2View(Q2Controller cont) {
|
|
||||||
this.cont = cont;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void view() {
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
|
||||||
System.out.println("メールアドレスを入力してください");
|
|
||||||
String mailAddress = scanner.nextLine();
|
|
||||||
|
|
||||||
System.out.println("パスワードを入力してください");
|
|
||||||
String password = scanner.nextLine();
|
|
||||||
|
|
||||||
String result = cont.show(mailAddress, password);
|
|
||||||
|
|
||||||
System.out.println(result);
|
|
||||||
scanner.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package com.example.demo.service;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Q2Entity;
|
|
||||||
import com.example.demo.persistence.Q2Dao;
|
|
||||||
|
|
||||||
public class Q2Service {
|
|
||||||
|
|
||||||
private Q2Dao dao;
|
|
||||||
|
|
||||||
public Q2Service(Q2Dao dao) {
|
|
||||||
this.dao = dao;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 引数を受け取り、DAOを実行して戻り値をコントローラーに返却
|
|
||||||
public Q2Entity handleUserData(String mailAddress, String password) {
|
|
||||||
// DAOクラスのメソッドに引数を渡して実行
|
|
||||||
Q2Entity entity = dao.createEntity(mailAddress, password);
|
|
||||||
// コントローラーに返却
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
spring.application.name=02-SpringFramework-2
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package com.example.demo.application;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Q1Entity;
|
|
||||||
import com.example.demo.logic.Q1Logic;
|
|
||||||
import com.example.demo.service.Q1Service;
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
public class Q1Controller {
|
|
||||||
@Autowired
|
|
||||||
Q1Service service;
|
|
||||||
@Autowired
|
|
||||||
Q1Logic logic;
|
|
||||||
|
|
||||||
public String show(String mailaddress, String password) {
|
|
||||||
if (mailaddress.length() > 256) {
|
|
||||||
return "メールアドレスもしくはパスワードが不正です";
|
|
||||||
}
|
|
||||||
if (password.length() < 8) {
|
|
||||||
return "メールアドレスもしくはパスワードが不正です";
|
|
||||||
}
|
|
||||||
// サービスクラスのメソッド実行
|
|
||||||
Q1Entity entityresult = service.handleUserData(mailaddress, password);
|
|
||||||
// サービスの戻り値をロジックに渡し、その戻り値をViewに返却
|
|
||||||
String result = logic.generateMessage(entityresult);
|
|
||||||
return result;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.example.demo.logic;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Q1Entity;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class Q1Logic {
|
|
||||||
// 引数を受け取り、指定の形式で文字列を作成して返却
|
|
||||||
public String generateMessage(Q1Entity entity) {
|
|
||||||
// 変更方式
|
|
||||||
String result = "メールアドレス:" + entity.getMailAddress() + "パスワード:" + entity.getPassword();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package com.example.demo.persistence;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Q1Entity;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public class Q1Dao {
|
|
||||||
|
|
||||||
// 引数を受け取り、Entityに格納して返却するメソッド
|
|
||||||
public Q1Entity createEntity(String mailaddress, String password) {
|
|
||||||
// インスタンスに格納
|
|
||||||
Q1Entity entity = new Q1Entity(mailaddress, password);
|
|
||||||
// サービスクラスに返却
|
|
||||||
return entity;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package com.example.demo.presentation;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import com.example.demo.application.Q1Controller;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class Q1View {
|
|
||||||
@Autowired
|
|
||||||
Q1Controller cont;
|
|
||||||
|
|
||||||
public void view() {
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
|
||||||
System.out.println("メールアドレスを入力してください");
|
|
||||||
String mailaddress = scanner.nextLine();
|
|
||||||
|
|
||||||
System.out.println("パスワードを入力してください");
|
|
||||||
String password = scanner.nextLine();
|
|
||||||
|
|
||||||
// コントローラークラスに引数を渡して実行
|
|
||||||
String result = cont.show(mailaddress, password);
|
|
||||||
// コントローラークラスからの戻り値を出力
|
|
||||||
System.out.println(result);
|
|
||||||
scanner.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.example.demo.service;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Q1Entity;
|
|
||||||
import com.example.demo.persistence.Q1Dao;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class Q1Service {
|
|
||||||
@Autowired
|
|
||||||
Q1Dao dao;
|
|
||||||
// 引数を受け取り、DAOを実行して戻り値をコントローラーに返却
|
|
||||||
public Q1Entity handleUserData(String mailaddress, String password) {
|
|
||||||
// DAOクラスのメソッドに引数を渡して実行
|
|
||||||
Q1Entity entity = dao.createEntity(mailaddress, password);
|
|
||||||
// コントローラーに返却
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package com.example.demo;
|
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
|
||||||
|
|
||||||
import com.example.demo.presentation.Q3View;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
|
||||||
public class Application {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
|
|
||||||
Q3View q3 = context.getBean(Q3View.class);
|
|
||||||
q3.view();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package com.example.demo.application;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Employee;
|
|
||||||
import com.example.demo.logic.Q3Logic;
|
|
||||||
import com.example.demo.service.Q3Service;
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
public class Q3Controller {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
Q3Service service;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
Q3Logic logic;
|
|
||||||
|
|
||||||
public String show(String mailAddress, String password) {
|
|
||||||
if (mailAddress.length() > 256) {
|
|
||||||
System.out.println("メールアドレスもしくはパスワードが不正です");
|
|
||||||
}
|
|
||||||
if (password.length() > 8) {
|
|
||||||
System.out.println("メールアドレスもしくはパスワードが不正です");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Employee> contresult = service.getEmployeeList();
|
|
||||||
|
|
||||||
String logicresult = logic.findEmployeeName(contresult, mailAddress, password);
|
|
||||||
|
|
||||||
return logicresult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
package com.example.demo.domain;
|
|
||||||
|
|
||||||
import jakarta.persistence.Column;
|
|
||||||
import jakarta.persistence.Entity;
|
|
||||||
import jakarta.persistence.GeneratedValue;
|
|
||||||
import jakarta.persistence.GenerationType;
|
|
||||||
import jakarta.persistence.Id;
|
|
||||||
import jakarta.persistence.Table;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Table(name = "employee")
|
|
||||||
public class Employee {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
@Column(name = "id_employee", nullable = false)
|
|
||||||
private Integer idEmployee;
|
|
||||||
@Column(name = "nm_employee", nullable = false)
|
|
||||||
private String nmEmployee;
|
|
||||||
@Column(name = "kn_employee", nullable = false)
|
|
||||||
private String knEmployee;
|
|
||||||
@Column(name = "mail_address", nullable = false)
|
|
||||||
private String mailAddress;
|
|
||||||
@Column(name = "password", nullable = false)
|
|
||||||
private String password;
|
|
||||||
@Column(name = "id_department", nullable = false)
|
|
||||||
private Integer idDepertment;
|
|
||||||
|
|
||||||
public Employee() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Employee(Integer idEmployee, String nmEmployee, String knEmployee, String mailAddress, String password,
|
|
||||||
Integer idDepertment) {
|
|
||||||
this.idEmployee = idEmployee;
|
|
||||||
this.nmEmployee = nmEmployee;
|
|
||||||
this.knEmployee = knEmployee;
|
|
||||||
this.mailAddress = mailAddress;
|
|
||||||
this.password = password;
|
|
||||||
this.idDepertment = idDepertment;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getIdEmployee() {
|
|
||||||
return idEmployee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIdEmployee(Integer idEmployee) {
|
|
||||||
this.idEmployee = idEmployee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNmEmployee() {
|
|
||||||
return nmEmployee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNmEmployee(String nmEmployee) {
|
|
||||||
this.nmEmployee = nmEmployee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getKnEmployee() {
|
|
||||||
return knEmployee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setKnEmployee(String knEmployee) {
|
|
||||||
this.knEmployee = knEmployee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMailAddress() {
|
|
||||||
return mailAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMailAddress(String mailAddress) {
|
|
||||||
this.mailAddress = mailAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getIdDepertment() {
|
|
||||||
return idDepertment;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIdDepertment(Integer idDepertment) {
|
|
||||||
this.idDepertment = idDepertment;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package com.example.demo.logic;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Employee;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class Q3Logic {
|
|
||||||
|
|
||||||
public String findEmployeeName(List<Employee> employeeList, String input_mailAddress, String input_password) {
|
|
||||||
|
|
||||||
for (Employee employee : employeeList) {
|
|
||||||
String targetmail = employee.getMailAddress();
|
|
||||||
String targetpass = employee.getPassword();
|
|
||||||
|
|
||||||
if (targetmail.equals(input_mailAddress) && targetpass.equals(input_password)) {
|
|
||||||
String FindName = employee.getNmEmployee();
|
|
||||||
return FindName;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
String errorMessage = "該当するデータはありません";
|
|
||||||
return errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package com.example.demo.persistence;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Employee;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface EmployeeRepository extends JpaRepository<Employee, Integer> {
|
|
||||||
|
|
||||||
default List<Employee> findAllEmployees() {
|
|
||||||
// employeeから全件取得し、インスタンスに格納
|
|
||||||
List<Employee> list = this.findAll();
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package com.example.demo.presentation;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import com.example.demo.application.Q3Controller;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class Q3View {
|
|
||||||
@Autowired
|
|
||||||
Q3Controller cont;
|
|
||||||
|
|
||||||
public void view() {
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
|
||||||
System.out.println("メールアドレスを入力してください");
|
|
||||||
String input_mailAddress = scanner.nextLine();
|
|
||||||
|
|
||||||
System.out.println("パスワードを入力してください");
|
|
||||||
String input_password = scanner.nextLine();
|
|
||||||
|
|
||||||
String result = cont.show(input_mailAddress, input_password);
|
|
||||||
System.out.println(result);
|
|
||||||
|
|
||||||
scanner.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.example.demo.service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Employee;
|
|
||||||
import com.example.demo.persistence.EmployeeRepository;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class Q3Service {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
EmployeeRepository dao;
|
|
||||||
|
|
||||||
public List<Employee> getEmployeeList() {
|
|
||||||
|
|
||||||
List<Employee> Daoresult = dao.findAllEmployees();
|
|
||||||
|
|
||||||
return Daoresult;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
spring.application.name=03_SpringFramework
|
|
||||||
spring.datasource.url=jdbc:mysql://localhost:3306/rezodb
|
|
||||||
spring.datasource.username=rezouser
|
|
||||||
spring.datasource.password=Rezo_0000
|
|
||||||
@@ -9,10 +9,10 @@
|
|||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.example</groupId>
|
<groupId>com.example</groupId>
|
||||||
<artifactId>02-SpringFramework-2</artifactId>
|
<artifactId>Spring-lesson-Q2</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<name>02-SpringFramework-2</name>
|
<name>Spring-lesson-Q2</name>
|
||||||
<description/>
|
<description/>
|
||||||
<url/>
|
<url/>
|
||||||
<licenses>
|
<licenses>
|
||||||
@@ -7,7 +7,7 @@ public class ServletInitializer extends SpringBootServletInitializer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||||
return application.sources(Application.class);
|
return application.sources(SpringLessonQ2Application.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.example.demo;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
|
||||||
|
import com.example.demo.presentation.Q2View;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class SpringLessonQ2Application {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// SpringLessonApplication.class မှ SpringLessonQ2Application.class သို့ ပြင်ဆင်ထားပါသည်
|
||||||
|
ConfigurableApplicationContext context = SpringApplication.run(SpringLessonQ2Application.class, args);
|
||||||
|
|
||||||
|
// Q2View Bean ကို ရယူပြီး display() ကို ခေါ်ယူခြင်း
|
||||||
|
Q2View view = context.getBean(Q2View.class);
|
||||||
|
view.display();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.example.demo.application;
|
||||||
|
|
||||||
|
import com.example.demo.domain.Q2Entity;
|
||||||
|
import com.example.demo.logic.Q2Logic;
|
||||||
|
import com.example.demo.service.Q2Service;
|
||||||
|
|
||||||
|
public class Q2Controller {
|
||||||
|
private final Q2Service q2Service;
|
||||||
|
private final Q2Logic q2Logic;
|
||||||
|
|
||||||
|
public Q2Controller(Q2Service q2Service, Q2Logic q2Logic) {
|
||||||
|
this.q2Service = q2Service;
|
||||||
|
this.q2Logic = q2Logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String execute(String mailAddress, String password) {
|
||||||
|
if (mailAddress != null && mailAddress.length() > 256) {
|
||||||
|
return "メールアドレスもしくはパスワードが不正です";
|
||||||
|
}
|
||||||
|
if (password != null && password.length() < 8) {
|
||||||
|
return "メールアドレスもしくはパスワードが不正です";
|
||||||
|
}
|
||||||
|
Q2Entity entity = q2Service.processService(mailAddress, password);
|
||||||
|
|
||||||
|
return q2Logic.formatUserDetail(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.example.demo.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import com.example.demo.application.Q2Controller;
|
||||||
|
import com.example.demo.logic.Q2Logic;
|
||||||
|
import com.example.demo.presentation.Q2View;
|
||||||
|
import com.example.demo.presistence.Q2Dao;
|
||||||
|
import com.example.demo.service.Q2Service;
|
||||||
|
|
||||||
|
@Configuration // ★ ဒီ Annotation မပါရင် Bean တွေကို ရှာမတွေ့ပါဘူး
|
||||||
|
public class Q2Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Q2Dao q2Dao() {
|
||||||
|
return new Q2Dao();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Q2Service q2Service() {
|
||||||
|
return new Q2Service(q2Dao());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Q2Logic q2Logic() {
|
||||||
|
return new Q2Logic();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Q2Controller q2Controller() {
|
||||||
|
return new Q2Controller(q2Service(), q2Logic());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Q2View q2View() {
|
||||||
|
return new Q2View(q2Controller());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.example.demo.domain;
|
package com.example.demo.domain;
|
||||||
|
|
||||||
public class Q2Entity {
|
public class Q2Entity {
|
||||||
|
|
||||||
private String mailAddress;
|
private String mailAddress;
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.example.demo.logic;
|
||||||
|
|
||||||
|
import com.example.demo.domain.Q2Entity;
|
||||||
|
|
||||||
|
public class Q2Logic {
|
||||||
|
|
||||||
|
public String formatUserDetail(Q2Entity entity) {
|
||||||
|
return "メールアドレス:" + entity.getMailAddress() + " パスワード:" + entity.getPassword();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.example.demo.presentation;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
import com.example.demo.application.Q2Controller;
|
||||||
|
|
||||||
|
public class Q2View {
|
||||||
|
private final Q2Controller q2Controller;
|
||||||
|
|
||||||
|
public Q2View(Q2Controller q2Controller) {
|
||||||
|
this.q2Controller = q2Controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void display() {
|
||||||
|
Scanner scan = new Scanner(System.in);
|
||||||
|
System.out.println("メール入力してください。");
|
||||||
|
String mailAddress = scan.nextLine().trim(); // trim() ထည့်ပေးပါ
|
||||||
|
|
||||||
|
System.out.println("パスワード入力してください。");
|
||||||
|
String password = scan.nextLine().trim(); // trim() ထည့်ပေးပါ
|
||||||
|
|
||||||
|
String result = q2Controller.execute(mailAddress, password);
|
||||||
|
System.out.println("");
|
||||||
|
System.out.println("===== 結果 =====");
|
||||||
|
System.out.println(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.example.demo.presistence;
|
||||||
|
|
||||||
|
import com.example.demo.domain.Q2Entity;
|
||||||
|
|
||||||
|
public class Q2Dao {
|
||||||
|
public Q2Entity createEntity(String mailAddress, String password) {
|
||||||
|
return new Q2Entity(mailAddress, password);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.example.demo.service;
|
||||||
|
|
||||||
|
import com.example.demo.domain.Q2Entity;
|
||||||
|
import com.example.demo.presistence.Q2Dao;
|
||||||
|
|
||||||
|
public class Q2Service {
|
||||||
|
private final Q2Dao q2Dao;
|
||||||
|
|
||||||
|
public Q2Service(Q2Dao q2Dao) {
|
||||||
|
this.q2Dao = q2Dao;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Q2Entity processService(String mailAddress, String password) {
|
||||||
|
return q2Dao.createEntity(mailAddress, password);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
spring.application.name=Spring-lesson-Q2
|
||||||
@@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class ApplicationTests {
|
class SpringLessonQ2ApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void contextLoads() {
|
void contextLoads() {
|
||||||
@@ -9,10 +9,10 @@
|
|||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.example</groupId>
|
<groupId>com.example</groupId>
|
||||||
<artifactId>03_SpringFramework-1</artifactId>
|
<artifactId>spring-lesson</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<name>03_SpringFramework-1</name>
|
<name>spring-lesson</name>
|
||||||
<description/>
|
<description/>
|
||||||
<url/>
|
<url/>
|
||||||
<licenses>
|
<licenses>
|
||||||
@@ -35,14 +35,6 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-validation</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-webmvc</artifactId>
|
<artifactId>spring-boot-starter-webmvc</artifactId>
|
||||||
@@ -74,21 +66,16 @@
|
|||||||
<artifactId>spring-boot-starter-data-jpa-test</artifactId>
|
<artifactId>spring-boot-starter-data-jpa-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-thymeleaf-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-validation-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-webmvc-test</artifactId>
|
<artifactId>spring-boot-starter-webmvc-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.example</groupId>
|
||||||
|
<artifactId>Spring-lesson-Q2</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -7,7 +7,7 @@ public class ServletInitializer extends SpringBootServletInitializer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||||
return application.sources(Application.class);
|
return application.sources(SpringLessonApplication.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,12 +7,14 @@ import org.springframework.context.ConfigurableApplicationContext;
|
|||||||
import com.example.demo.presentation.Q1View;
|
import com.example.demo.presentation.Q1View;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class Application {
|
public class SpringLessonApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
|
ConfigurableApplicationContext context = SpringApplication.run(SpringLessonApplication.class, args);
|
||||||
Q1View sample = context.getBean(Q1View.class);
|
|
||||||
sample.view();
|
// Q1View Bean ကို ရယူပြီး Execute လုပ်ခြင်း
|
||||||
|
Q1View view = context.getBean(Q1View.class);
|
||||||
|
view.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.example.demo.application;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
|
||||||
|
import com.example.demo.domain.Q1Entity;
|
||||||
|
import com.example.demo.logic.Q1Logic;
|
||||||
|
import com.example.demo.service.Q1Service;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class Q1Controller {
|
||||||
|
@Autowired
|
||||||
|
private Q1Service q1Service;
|
||||||
|
@Autowired
|
||||||
|
private Q1Logic q1Logic;
|
||||||
|
|
||||||
|
public String execute (String mailAddress, String password) {
|
||||||
|
Q1Entity entity =q1Service.processService(mailAddress, password);
|
||||||
|
|
||||||
|
return q1Logic.formatUserDetail(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,32 +5,35 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
|
|
||||||
import com.example.demo.application.Q2Controller;
|
import com.example.demo.application.Q2Controller;
|
||||||
import com.example.demo.logic.Q2Logic;
|
import com.example.demo.logic.Q2Logic;
|
||||||
import com.example.demo.persistence.Q2Dao;
|
|
||||||
import com.example.demo.presentation.Q2View;
|
import com.example.demo.presentation.Q2View;
|
||||||
|
import com.example.demo.presistence.Q2Dao;
|
||||||
import com.example.demo.service.Q2Service;
|
import com.example.demo.service.Q2Service;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class Q2Config {
|
public class Q2Config {
|
||||||
@Bean
|
|
||||||
public Q2Controller q2Controller(Q2Service service, Q2Logic logic) {
|
|
||||||
return new Q2Controller(service, logic);
|
|
||||||
}
|
|
||||||
@Bean
|
|
||||||
public Q2View view(Q2Controller cont) {
|
|
||||||
return new Q2View(cont);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Q2Service q2Service(Q2Dao dao) {
|
|
||||||
return new Q2Service(dao);
|
|
||||||
}
|
|
||||||
@Bean
|
@Bean
|
||||||
public Q2Dao q2Dao() {
|
public Q2Dao q2Dao() {
|
||||||
return new Q2Dao();
|
return new Q2Dao();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Q2Service q2Service() {
|
||||||
|
return new Q2Service(q2Dao());
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Q2Logic q2Logic() {
|
public Q2Logic q2Logic() {
|
||||||
return new Q2Logic();
|
return new Q2Logic();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Q2Controller q2Controller() {
|
||||||
|
return new Q2Controller(q2Service(), q2Logic());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Q2View q2View() {
|
||||||
|
return new Q2View(q2Controller());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,24 @@
|
|||||||
package com.example.demo.domain;
|
package com.example.demo.domain;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
|
||||||
|
@Entity
|
||||||
public class Q1Entity {
|
public class Q1Entity {
|
||||||
|
@Id
|
||||||
private String mailAddress;
|
private String mailAddress;
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
public Q1Entity(String mailaddress, String password) {
|
public Q1Entity() {
|
||||||
this.mailAddress = mailaddress;
|
}
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
public Q1Entity(String mailAddress, String password) {
|
||||||
|
this.mailAddress = mailAddress;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Getter & Setter
|
||||||
public String getMailAddress() {
|
public String getMailAddress() {
|
||||||
return mailAddress;
|
return mailAddress;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.example.demo.logic;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.example.demo.domain.Q1Entity;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class Q1Logic {
|
||||||
|
public String formatUserDetail(Q1Entity entity) {
|
||||||
|
return"メールアドレス:"+entity.getMailAddress()+" パスワード:"+entity.getPassword();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.example.demo.persistence;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import com.example.demo.domain.Q1Entity;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class Q1Dao {
|
||||||
|
private Q1Dao q1Dao;
|
||||||
|
public Q1Entity createEntity (String mailAddress, String password) {
|
||||||
|
return new Q1Entity(mailAddress, password);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.example.demo.presentation;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.example.demo.application.Q1Controller;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class Q1View {
|
||||||
|
@Autowired
|
||||||
|
private Q1Controller q1Controller;
|
||||||
|
|
||||||
|
public void display() {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
System.out.println("メールアドレス入力してください。");
|
||||||
|
String mailAdress = scanner.nextLine();
|
||||||
|
System.out.println("パスワード入力してください。");
|
||||||
|
String password = scanner.nextLine();
|
||||||
|
|
||||||
|
String result = q1Controller.execute(mailAdress, password);
|
||||||
|
System.out.println("======結果=====");
|
||||||
|
System.out.println(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.example.demo.service;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.example.demo.domain.Q1Entity;
|
||||||
|
import com.example.demo.persistence.Q1Dao;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class Q1Service {
|
||||||
|
@Autowired
|
||||||
|
private Q1Dao q1Dao;
|
||||||
|
public Q1Entity processService(String mailAdress, String password) {
|
||||||
|
return q1Dao.createEntity(mailAdress,password);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
5
spring-lesson/src/main/resources/application.properties
Normal file
5
spring-lesson/src/main/resources/application.properties
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
spring.application.name=spring-lesson
|
||||||
|
spring.datasource.url=jdbc:mysql://localhost:3306/rezodb
|
||||||
|
spring.datasource.username=rezouser
|
||||||
|
spring.datasource.password=Rezo_0000
|
||||||
|
spring.application.admin.enabled=false
|
||||||
@@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class ApplicationTests {
|
class SpringLessonApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void contextLoads() {
|
void contextLoads() {
|
||||||
Reference in New Issue
Block a user