Q2終了
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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,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;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
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
|
||||
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 Q2Logic q2Logic() {
|
||||
return new Q2Logic();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.example.demo;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class ApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user