This commit is contained in:
2026-10-07 16:20:16 +09:00
parent ed7b0eacd4
commit a2fe934995
9 changed files with 200 additions and 0 deletions

View File

@@ -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 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();
}
}

View File

@@ -0,0 +1,30 @@
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;
}
}
}

View File

@@ -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.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();
}
}

View File

@@ -0,0 +1,29 @@
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;
}
}

View File

@@ -0,0 +1,12 @@
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;
}
}

View File

@@ -0,0 +1,13 @@
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;
}
}

View File

@@ -0,0 +1,26 @@
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);
}
}

View File

@@ -0,0 +1,17 @@
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;
}
}

View File

@@ -0,0 +1,13 @@
package com.example.demo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class SpringQuestion2ApplicationTests {
@Test
void contextLoads() {
}
}