Q1終了
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.Q1View;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
|
||||||
|
Q1View sample = context.getBean(Q1View.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 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;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.example.demo.domain;
|
||||||
|
|
||||||
|
public class Q1Entity {
|
||||||
|
private String mailAddress;
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user