Compare commits
3 Commits
f9456bf9e7
...
t-eguchi
| Author | SHA1 | Date | |
|---|---|---|---|
| 7675e0f4fa | |||
| b9964d5229 | |||
| ce3f467c93 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +0,0 @@
|
||||
/.metadata/
|
||||
@@ -9,10 +9,10 @@
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>Spring-lesson-Q2</artifactId>
|
||||
<artifactId>02-SpringFramework-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
<name>Spring-lesson-Q2</name>
|
||||
<name>02-SpringFramework-2</name>
|
||||
<description/>
|
||||
<url/>
|
||||
<licenses>
|
||||
@@ -0,0 +1,18 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,7 +7,7 @@ public class ServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(SpringLessonApplication.class);
|
||||
return application.sources(Application.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,35 +5,32 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.example.demo.application.Q2Controller;
|
||||
import com.example.demo.logic.Q2Logic;
|
||||
import com.example.demo.persistence.Q2Dao;
|
||||
import com.example.demo.presentation.Q2View;
|
||||
import com.example.demo.presistence.Q2Dao;
|
||||
import com.example.demo.service.Q2Service;
|
||||
|
||||
@Configuration
|
||||
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
|
||||
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,10 +1,9 @@
|
||||
package com.example.demo.domain;
|
||||
|
||||
public class Q2Entity {
|
||||
|
||||
private String mailAddress;
|
||||
private String password;
|
||||
|
||||
|
||||
public Q2Entity(String mailAddress, String password) {
|
||||
this.mailAddress = mailAddress;
|
||||
this.password = password;
|
||||
@@ -25,5 +24,5 @@ public class Q2Entity {
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
spring.application.name=02-SpringFramework-2
|
||||
@@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class SpringLessonApplicationTests {
|
||||
class ApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
@@ -7,14 +7,12 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import com.example.demo.presentation.Q1View;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringLessonApplication {
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ConfigurableApplicationContext context = SpringApplication.run(SpringLessonApplication.class, args);
|
||||
|
||||
// Q1View Bean ကို ရယူပြီး Execute လုပ်ခြင်း
|
||||
Q1View view = context.getBean(Q1View.class);
|
||||
view.display();
|
||||
ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
|
||||
Q1View sample = context.getBean(Q1View.class);
|
||||
sample.view();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,7 +7,7 @@ public class ServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(SpringLessonQ2Application.class);
|
||||
return application.sources(Application.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
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,24 +1,14 @@
|
||||
package com.example.demo.domain;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class Q1Entity {
|
||||
@Id
|
||||
private String mailAddress;
|
||||
private String password;
|
||||
|
||||
public Q1Entity() {
|
||||
}
|
||||
|
||||
// Constructor
|
||||
public Q1Entity(String mailAddress, String password) {
|
||||
this.mailAddress = mailAddress;
|
||||
public Q1Entity(String mailaddress, String password) {
|
||||
this.mailAddress = mailaddress;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
// Getter & Setter
|
||||
public String getMailAddress() {
|
||||
return mailAddress;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,10 @@
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>spring-lesson</artifactId>
|
||||
<artifactId>03_SpringFramework-1</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
<name>spring-lesson</name>
|
||||
<name>03_SpringFramework-1</name>
|
||||
<description/>
|
||||
<url/>
|
||||
<licenses>
|
||||
@@ -35,6 +35,14 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</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>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webmvc</artifactId>
|
||||
@@ -68,13 +76,18 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webmvc-test</artifactId>
|
||||
<artifactId>spring-boot-starter-thymeleaf-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>Spring-lesson-Q2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webmvc-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
spring.application.name=03_SpringFramework
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/rezodb
|
||||
spring.datasource.username=rezouser
|
||||
spring.datasource.password=Rezo_0000
|
||||
@@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class SpringLessonQ2ApplicationTests {
|
||||
class ApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
@@ -1,21 +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 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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,27 +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 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);
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
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,10 +0,0 @@
|
||||
package com.example.demo.logic;
|
||||
|
||||
import com.example.demo.domain.Q2Entity;
|
||||
|
||||
public class Q2Logic {
|
||||
|
||||
public String formatUserDetail(Q2Entity entity) {
|
||||
return "メールアドレス:" + entity.getMailAddress() + " パスワード:" + entity.getPassword();
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
spring.application.name=Spring-lesson-Q2
|
||||
@@ -1,23 +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
|
||||
private Q1Service q1Service;
|
||||
@Autowired
|
||||
private Q1Logic q1Logic;
|
||||
|
||||
public String execute (String mailAddress, String password) {
|
||||
Q1Entity entity =q1Service.processService(mailAddress, password);
|
||||
|
||||
return q1Logic.formatUserDetail(entity);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +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
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +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
|
||||
private Q1Dao q1Dao;
|
||||
public Q1Entity processService(String mailAdress, String password) {
|
||||
return q1Dao.createEntity(mailAdress,password);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
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
|
||||
Reference in New Issue
Block a user