Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1cfeb3101d |
@@ -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 org.springframework.context.annotation.Import;
|
|
||||||
|
|
||||||
import com.example.demo.config.Q2Config;
|
|
||||||
import com.example.demo.presentation.Q2View;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
|
||||||
@Import(Q2Config.class)
|
|
||||||
public class SpringQuestion2Application {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
ConfigurableApplicationContext context = SpringApplication.run(SpringQuestion2Application.class, args);
|
|
||||||
Q2View sample = context.getBean(Q2View.class);
|
|
||||||
sample.Empscan();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package com.example.demo.application;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Q2Entity;
|
|
||||||
import com.example.demo.logic.Q2Logic;
|
|
||||||
import com.example.demo.service.Q2Service;
|
|
||||||
|
|
||||||
public class Q2Controller {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
Q2Service serv;
|
|
||||||
@Autowired
|
|
||||||
Q2Logic logic;
|
|
||||||
|
|
||||||
public String Empjudge(String mailadress, String password) {
|
|
||||||
String message;
|
|
||||||
//パスワードとメールアドレスが正確かジャッジ
|
|
||||||
if (mailadress.length() > 256 || password.length() < 8) {
|
|
||||||
message = "メールアドレスもしくはパスワードが不正です";
|
|
||||||
return message;
|
|
||||||
} else {
|
|
||||||
//サービスメソッドに引数を渡し実行
|
|
||||||
Q2Entity entity = serv.ServeEntity(mailadress, password);
|
|
||||||
//ロジッククラスに引数を渡し実行
|
|
||||||
message = logic.Createmessage(entity);
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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.persistence.Q2Dao;
|
|
||||||
import com.example.demo.presentation.Q2View;
|
|
||||||
import com.example.demo.service.Q2Service;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class Q2Config {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
Q2Dao q2dao() {
|
|
||||||
return new Q2Dao();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
Q2Service q2service() {
|
|
||||||
return new Q2Service();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
Q2Logic q2logic() {
|
|
||||||
return new Q2Logic();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
Q2Controller q2controller() {
|
|
||||||
return new Q2Controller();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
Q2View q2view() {
|
|
||||||
return new Q2View();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package com.example.demo.domain;
|
|
||||||
|
|
||||||
|
|
||||||
public class Q2Entity {
|
|
||||||
private String mailAdress;
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
public Q2Entity(String mailAdress, String password) {
|
|
||||||
this.mailAdress = mailAdress;
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMailAdress() {
|
|
||||||
return mailAdress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMailAdress(String mailAdress) {
|
|
||||||
this.mailAdress = mailAdress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.example.demo.logic;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Q2Entity;
|
|
||||||
|
|
||||||
public class Q2Logic {
|
|
||||||
public String Createmessage(Q2Entity entity) {
|
|
||||||
//引数をもとにメッセージの作成
|
|
||||||
String message;
|
|
||||||
message = "メールアドレス:" + entity.getMailAdress() + " パスワード:" + entity.getPassword();
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.example.demo.persistence;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Q2Entity;
|
|
||||||
|
|
||||||
public class Q2Dao {
|
|
||||||
//サービスクラスから引数を受け取る
|
|
||||||
public Q2Entity CreateEntity(String mailaddres, String password) {
|
|
||||||
//受け取った引数をエンティティクラス型のインスタンスに格納
|
|
||||||
Q2Entity entity = new Q2Entity(mailaddres, password);
|
|
||||||
//格納したインスタンスをサービスクラスに戻り値として返却
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package com.example.demo.presentation;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
import com.example.demo.application.Q2Controller;
|
|
||||||
|
|
||||||
public class Q2View {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
Q2Controller cont;
|
|
||||||
|
|
||||||
public void Empscan() {
|
|
||||||
//メールアドレスとパスワードの入力
|
|
||||||
System.out.println("メールアドレスを入力してください");
|
|
||||||
Scanner sc = new Scanner(System.in);
|
|
||||||
String Mailadress = sc.nextLine();
|
|
||||||
System.out.println("パスワードを入力してください");
|
|
||||||
String Password = sc.nextLine();
|
|
||||||
//入力した値をコントローラークラスのメソッドに引数として渡し、実行
|
|
||||||
String message = cont.Empjudge(Mailadress, Password);
|
|
||||||
System.out.println(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package com.example.demo.service;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Q2Entity;
|
|
||||||
import com.example.demo.persistence.Q2Dao;
|
|
||||||
|
|
||||||
public class Q2Service {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
Q2Dao dao;
|
|
||||||
//エンティティクラスに引数を渡し実行
|
|
||||||
public Q2Entity ServeEntity(String mailaddres, String password) {
|
|
||||||
Q2Entity entity = dao.CreateEntity(mailaddres, password);
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.example.demo;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
class SpringQuestion2ApplicationTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void contextLoads() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package com.example.demo.application;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Q1Entity;
|
|
||||||
import com.example.demo.logic.Q1Logic;
|
|
||||||
import com.example.demo.service.Q1Service;
|
|
||||||
|
|
||||||
public class SampleController {
|
|
||||||
|
|
||||||
public String Empjudge(String mailadress, String password) {
|
|
||||||
String message;
|
|
||||||
//パスワードとメールアドレスが正確かジャッジ
|
|
||||||
if (mailadress.length() > 256 || password.length() < 8) {
|
|
||||||
message = "メールアドレスもしくはパスワードが不正です";
|
|
||||||
return message;
|
|
||||||
} else {
|
|
||||||
//サービスメソッドに引数を渡し実行
|
|
||||||
Q1Entity entity = Q1Service.ServeEntity(mailadress, password);
|
|
||||||
//ロジッククラスに引数を渡し実行
|
|
||||||
message = Q1Logic.Createmessage(entity);
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package com.example.demo.domain;
|
|
||||||
|
|
||||||
public class Q1Entity {
|
|
||||||
private String mailAdress;
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
public Q1Entity(String mailAdress, String password) {
|
|
||||||
this.mailAdress = mailAdress;
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMailAdress() {
|
|
||||||
return mailAdress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMailAdress(String mailAdress) {
|
|
||||||
this.mailAdress = mailAdress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.example.demo.logic;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Q1Entity;
|
|
||||||
|
|
||||||
public class Q1Logic {
|
|
||||||
public static String Createmessage(Q1Entity entity) {
|
|
||||||
//引数をもとにメッセージの作成
|
|
||||||
String message;
|
|
||||||
message = "メールアドレス:" + entity.getMailAdress() + " パスワード:" + entity.getPassword();
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.example.demo.persistence;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Q1Entity;
|
|
||||||
|
|
||||||
public class Q1Dao {
|
|
||||||
//サービスクラスから引数を受け取る
|
|
||||||
public static Q1Entity CreateEntity(String mailaddres, String password) {
|
|
||||||
//受け取った引数をエンティティクラス型のインスタンスに格納
|
|
||||||
Q1Entity entity = new Q1Entity(mailaddres, password);
|
|
||||||
//格納したインスタンスをサービスクラスに戻り値として返却
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package com.example.demo.presentaiton;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
import com.example.demo.application.SampleController;
|
|
||||||
|
|
||||||
public class Q1View {
|
|
||||||
SampleController cont = new SampleController();
|
|
||||||
|
|
||||||
public void Empscan() {
|
|
||||||
//メールアドレスとパスワードの入力
|
|
||||||
System.out.println("メールアドレスを入力してください");
|
|
||||||
Scanner sc = new Scanner(System.in);
|
|
||||||
String Mailadress = sc.nextLine();
|
|
||||||
System.out.println("パスワードを入力してください");
|
|
||||||
String Password = sc.nextLine();
|
|
||||||
//入力した値をコントローラークラスのメソッドに引数として渡し、実行
|
|
||||||
String message = cont.Empjudge(Mailadress, Password);
|
|
||||||
System.out.println(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.example.demo.service;
|
|
||||||
|
|
||||||
import com.example.demo.domain.Q1Entity;
|
|
||||||
import com.example.demo.persistence.Q1Dao;
|
|
||||||
|
|
||||||
public class Q1Service {
|
|
||||||
//エンティティクラスに引数を渡し実行
|
|
||||||
public static Q1Entity ServeEntity(String mailaddres, String password) {
|
|
||||||
Q1Entity entity = Q1Dao.CreateEntity(mailaddres, password);
|
|
||||||
return entity;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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 org.springframework.context.annotation.ComponentScan;
|
|
||||||
|
|
||||||
import com.example.demo.presentation.Q3View;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
|
||||||
@ComponentScan
|
|
||||||
public class SpringQuestion3Application {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
ConfigurableApplicationContext context =
|
|
||||||
SpringApplication.run(SpringQuestion3Application.class, args);
|
|
||||||
Q3View view = context.getBean(Q3View.class);
|
|
||||||
view.Empscan();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,33 +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 serv;
|
|
||||||
@Autowired
|
|
||||||
Q3Logic logic;
|
|
||||||
|
|
||||||
public String Empjudge(String mailadress, String password) {
|
|
||||||
String message;
|
|
||||||
//パスワードとメールアドレスが正確かジャッジ
|
|
||||||
if (mailadress.length() > 256 ) {
|
|
||||||
message = "メールアドレスもしくはパスワードが不正です";
|
|
||||||
return message;
|
|
||||||
} else {
|
|
||||||
//サービスクラスのメソッド実行
|
|
||||||
List<Employee> list= serv.getuserDate();
|
|
||||||
//ロジッククラスに引数を渡し実行
|
|
||||||
message = logic.Createmessage(mailadress, password, list);
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +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 Createmessage(String mailadress, String password, List<Employee> list) {
|
|
||||||
for (Employee emp : list) {
|
|
||||||
if (mailadress.equals(emp.getMailAddress())
|
|
||||||
&& password.equals(emp.getPassword())) {
|
|
||||||
return emp.getNmEmployee();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "該当のデータが存在しません。";
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package com.example.demo.persistence;
|
|
||||||
|
|
||||||
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> {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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.Q3Controller;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class Q3View {
|
|
||||||
@Autowired
|
|
||||||
Q3Controller cont;
|
|
||||||
|
|
||||||
public void Empscan() {
|
|
||||||
//メールアドレスとパスワードの入力
|
|
||||||
System.out.println("メールアドレスを入力してください");
|
|
||||||
Scanner sc = new Scanner(System.in);
|
|
||||||
String Mailadress = sc.nextLine();
|
|
||||||
System.out.println("パスワードを入力してください");
|
|
||||||
String Password = sc.nextLine();
|
|
||||||
//入力した値をコントローラークラスのメソッドに引数として渡し、実行
|
|
||||||
String message = cont.Empjudge(Mailadress, Password);
|
|
||||||
System.out.println(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +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> getuserDate(){
|
|
||||||
return dao.findAll();//インタフェースに搭載されている全検索メソッド
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
spring.application.name=SpringQuestion3
|
|
||||||
spring.datasource.url=jdbc:mysql://localhost:3306/rezodb
|
|
||||||
spring.datasource.username=rezouser
|
|
||||||
spring.datasource.password=Rezo_0000
|
|
||||||
0
SpringQuestion3/mvnw → spring-Q1/mvnw
vendored
0
SpringQuestion3/mvnw → spring-Q1/mvnw
vendored
@@ -9,9 +9,10 @@
|
|||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.example</groupId>
|
<groupId>com.example</groupId>
|
||||||
<artifactId>SpringQuestion3</artifactId>
|
<artifactId>spring-Q1</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<name>SpringQuestion3</name>
|
<packaging>war</packaging>
|
||||||
|
<name>spring-Q1</name>
|
||||||
<description/>
|
<description/>
|
||||||
<url/>
|
<url/>
|
||||||
<licenses>
|
<licenses>
|
||||||
@@ -32,17 +33,17 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
<artifactId>spring-boot-starter-webmvc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mysql</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>mysql-connector-j</artifactId>
|
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||||
<scope>runtime</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-jpa-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@@ -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(SpringQ1Application.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,14 +3,11 @@ package com.example.demo;
|
|||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
import com.example.demo.presentaiton.Q1View;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class SpringQuestionApplication {
|
public class SpringQ1Application {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(SpringQuestionApplication.class, args);
|
SpringApplication.run(SpringQ1Application.class, args);
|
||||||
new Q1View().Empscan();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.example.demo.application;
|
||||||
|
|
||||||
|
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 {
|
||||||
|
//sarviceクラスとlogicクラスをコンストラクタ経由で手動
|
||||||
|
private final Q1Service service;
|
||||||
|
private final Q1Logic logic;
|
||||||
|
|
||||||
|
public Q1Controller(Q1Service service, Q1Logic logic) {
|
||||||
|
this.service = service;
|
||||||
|
this.logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String checkLogin(String email, String password) {
|
||||||
|
//メールアドレスが256文字より大きい場合のエラーメッセージ
|
||||||
|
if (email.length() > 256) {
|
||||||
|
return "メールアドレスもしくはパスワードが不正です";
|
||||||
|
}
|
||||||
|
//パスワードが8文字より小さい場合のエラーメッセージ
|
||||||
|
if (password.length() < 8) {
|
||||||
|
return "メールアドレスもしくはパスワードが不正です";
|
||||||
|
}
|
||||||
|
//Serviceクラスのメソッドの引数にアドレスとパスワードを渡す
|
||||||
|
Q1Entity serviceResult = service.authenticateUser(email, password);
|
||||||
|
//Serviceクラスのメソッドの戻り値をLogicクラスのメソッドに引数として渡す
|
||||||
|
String logicResult = logic.formatLoginInfo(serviceResult);
|
||||||
|
//Logicクラスのメソッドの戻り値をViewクラスへ返却
|
||||||
|
return logicResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.example.demo.domain;
|
||||||
|
|
||||||
|
public class Q1Entity {
|
||||||
|
//フィールド宣言
|
||||||
|
private String mailAddress;
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
// //引数なしのコンストラクタ
|
||||||
|
// public Q1Entity() {
|
||||||
|
// }
|
||||||
|
|
||||||
|
//コンストラクタで上記フィールド初期化
|
||||||
|
public Q1Entity(String mailAddress, String password) {
|
||||||
|
this.mailAddress = mailAddress;
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
//ゲッター・セッター作成
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
14
spring-Q1/src/main/java/com/example/demo/logic/Q1Logic.java
Normal file
14
spring-Q1/src/main/java/com/example/demo/logic/Q1Logic.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package com.example.demo.logic;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.example.demo.domain.Q1Entity;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class Q1Logic {
|
||||||
|
//formatメソッド作成
|
||||||
|
public String formatLoginInfo(Q1Entity entity) {
|
||||||
|
//引数の内容から文字列作成、Controllerクラスへ返却
|
||||||
|
return "メールアドレス:" + entity.getMailAddress() + "パスワード:" + entity.getPassword();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.example.demo.persistence;
|
||||||
|
|
||||||
|
import com.example.demo.domain.Q1Entity;
|
||||||
|
|
||||||
|
public class Q1Dao {
|
||||||
|
//serviceクラスから渡ってきた引数の引き取り
|
||||||
|
public Q1Entity createEntity(String email, String password) {
|
||||||
|
//エンティティのインスタンス化
|
||||||
|
Q1Entity entity = new Q1Entity(email, password);
|
||||||
|
//セッターで引数を格納
|
||||||
|
entity.setMailAddress(email);
|
||||||
|
entity.setPassword(password);
|
||||||
|
//格納したインスタンスをserviceクラスへ戻り値として返却
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.example.demo.presentation;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.example.demo.application.Q1Controller;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class Q1View {
|
||||||
|
|
||||||
|
//Controllerクラスコンストラクタ経由で手動注入
|
||||||
|
private final Q1Controller cont;
|
||||||
|
|
||||||
|
public Q1View(Q1Controller cont) {
|
||||||
|
this.cont = cont;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Q1Displayメソッドを定義
|
||||||
|
public void display() {
|
||||||
|
//java.util.Scannerクラスの変数scanner準備
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
//メールアドレス入力、入力受け取り
|
||||||
|
System.out.println("メールアドレスを入力してください");
|
||||||
|
String email = scanner.nextLine();
|
||||||
|
//パスワード入力、入力受け取り
|
||||||
|
System.out.println("パスワードを入力してください");
|
||||||
|
String password = scanner.nextLine();
|
||||||
|
//Controllerクラスのメソッド戻り値
|
||||||
|
String result = cont.checkLogin(email, password);
|
||||||
|
//Controllerクラスの戻り値を出力
|
||||||
|
System.out.println(result);
|
||||||
|
//Scanner終了
|
||||||
|
scanner.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.example.demo.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.example.demo.domain.Q1Entity;
|
||||||
|
import com.example.demo.persistence.Q1Dao;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class Q1Service {
|
||||||
|
//daoクラスをコンストラクタ経由で手動注入
|
||||||
|
private final Q1Dao dao;
|
||||||
|
|
||||||
|
public Q1Service(Q1Dao dao) {
|
||||||
|
this.dao = dao;
|
||||||
|
}
|
||||||
|
|
||||||
|
//controllerクラスからの引数受け取り
|
||||||
|
public Q1Entity authenticateUser(String email, String password) {
|
||||||
|
//daoクラスのメソッドへ引数として渡す
|
||||||
|
Q1Entity checkLogin = dao.createEntity(email, password);
|
||||||
|
//Daoクラスからの戻り値をControllerクラスへ返却
|
||||||
|
return checkLogin;
|
||||||
|
}
|
||||||
|
}
|
||||||
1
spring-Q1/src/main/resources/application.properties
Normal file
1
spring-Q1/src/main/resources/application.properties
Normal file
@@ -0,0 +1 @@
|
|||||||
|
spring.application.name=spring-Q1
|
||||||
@@ -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 SpringQuestion3ApplicationTests {
|
class SpringQ1ApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void contextLoads() {
|
void contextLoads() {
|
||||||
Reference in New Issue
Block a user