Q2
This commit is contained in:
@@ -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(SpringLessonQ2Application.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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.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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
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,10 @@
|
||||
package com.example.demo.logic;
|
||||
|
||||
import com.example.demo.domain.Q2Entity;
|
||||
|
||||
public class Q2Logic {
|
||||
|
||||
public String formatUserDetail(Q2Entity entity) {
|
||||
return "メールアドレス:" + entity.getMailAddress() + " パスワード:" + entity.getPassword();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
spring.application.name=Spring-lesson-Q2
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.example.demo;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class SpringLessonQ2ApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user