Spring_Q1
This commit is contained in:
@@ -9,10 +9,10 @@
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>spring-lesson</artifactId>
|
||||
<artifactId>Spring-lesson</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
<name>spring-lesson</name>
|
||||
<name>Spring-lesson</name>
|
||||
<description/>
|
||||
<url/>
|
||||
<licenses>
|
||||
@@ -31,10 +31,7 @@
|
||||
<java.version>21</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webmvc</artifactId>
|
||||
@@ -46,36 +43,18 @@
|
||||
<scope>runtime</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webmvc-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>Spring-lesson-Q2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.example.demo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import com.example.demo.presentation.Q1View;
|
||||
|
||||
@@ -10,9 +10,9 @@ import com.example.demo.presentation.Q1View;
|
||||
public class SpringLessonApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ConfigurableApplicationContext context = SpringApplication.run(SpringLessonApplication.class, args);
|
||||
|
||||
// Q1View Bean ကို ရယူပြီး Execute လုပ်ခြင်း
|
||||
ApplicationContext context = SpringApplication.run(SpringLessonApplication.class, args);
|
||||
|
||||
Q1View view = context.getBean(Q1View.class);
|
||||
view.display();
|
||||
}
|
||||
|
||||
@@ -9,15 +9,21 @@ import com.example.demo.service.Q1Service;
|
||||
|
||||
@Controller
|
||||
public class Q1Controller {
|
||||
@Autowired
|
||||
private Q1Service q1Service;
|
||||
@Autowired
|
||||
private Q1Logic q1Logic;
|
||||
|
||||
public String execute (String mailAddress, String password) {
|
||||
Q1Entity entity =q1Service.processService(mailAddress, password);
|
||||
@Autowired
|
||||
Q1Service service;
|
||||
|
||||
return q1Logic.formatUserDetail(entity);
|
||||
Q1Logic logic = new Q1Logic();
|
||||
|
||||
public Q1Entity show(String mailAddress, String password) {
|
||||
String result = logic.check(mailAddress, password);
|
||||
|
||||
if (!result.equals("OK")) {
|
||||
System.out.println(result);
|
||||
return null;
|
||||
}
|
||||
|
||||
return service.getUserData(mailAddress, password);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,24 +1,20 @@
|
||||
package com.example.demo.domain;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class Q1Entity {
|
||||
@Id
|
||||
|
||||
private String mailAddress;
|
||||
private String password;
|
||||
|
||||
//↓これなんでいるんやろう
|
||||
public Q1Entity() {
|
||||
}
|
||||
|
||||
// Constructor
|
||||
public Q1Entity(String mailAddress, String password) {
|
||||
this.mailAddress = mailAddress;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
// Getter & Setter
|
||||
//getter・setter
|
||||
public String getMailAddress() {
|
||||
return mailAddress;
|
||||
}
|
||||
@@ -34,4 +30,5 @@ public class Q1Entity {
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
package com.example.demo.logic;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.example.demo.domain.Q1Entity;
|
||||
|
||||
@Component
|
||||
public class Q1Logic {
|
||||
public String formatUserDetail(Q1Entity entity) {
|
||||
return"メールアドレス:"+entity.getMailAddress()+" パスワード:"+entity.getPassword();
|
||||
public String check(String mailAddress, String password) {
|
||||
|
||||
//メールアドレスが256文字より大きい
|
||||
if (mailAddress.length() > 256) {
|
||||
return "メールアドレスもしくはパスワードが不正です";
|
||||
}
|
||||
|
||||
//パスワードが8文字より小さい
|
||||
if (password.length() < 8) {
|
||||
return "メールアドレスもしくはパスワードが不正です";
|
||||
}
|
||||
|
||||
return "OK";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@ import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.example.demo.domain.Q1Entity;
|
||||
|
||||
@Repository
|
||||
@Repository //←「このクラスはDAOとして使います」
|
||||
public class Q1Dao {
|
||||
private Q1Dao q1Dao;
|
||||
public Q1Entity createEntity (String mailAddress, String password) {
|
||||
return new Q1Entity(mailAddress, password);
|
||||
public Q1Entity findData(String mailAddress, String password) {
|
||||
|
||||
Q1Entity entity = new Q1Entity();
|
||||
|
||||
entity.setMailAddress(mailAddress);
|
||||
entity.setPassword(password);
|
||||
return entity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//メールアドレスとパスワードを入力する
|
||||
package com.example.demo.presentation;
|
||||
|
||||
import java.util.Scanner;
|
||||
@@ -6,21 +7,31 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.example.demo.application.Q1Controller;
|
||||
import com.example.demo.domain.Q1Entity;
|
||||
|
||||
@Component
|
||||
public class Q1View {
|
||||
@Autowired
|
||||
private Q1Controller q1Controller;
|
||||
|
||||
public void display() {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.println("メールアドレス入力してください。");
|
||||
String mailAdress = scanner.nextLine();
|
||||
System.out.println("パスワード入力してください。");
|
||||
String password = scanner.nextLine();
|
||||
@Autowired
|
||||
Q1Controller controller;
|
||||
|
||||
public void display() {
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
System.out.println("メールアドレス:");
|
||||
String mailAddress = scanner.nextLine();
|
||||
|
||||
System.out.println("パスワード:");
|
||||
String password = scanner.nextLine();
|
||||
|
||||
Q1Entity entity = controller.show(mailAddress, password);
|
||||
|
||||
if (entity != null) {
|
||||
System.out.println("メールアドレス:" + entity.getMailAddress());
|
||||
System.out.println("パスワード:" + entity.getPassword());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String result = q1Controller.execute(mailAdress, password);
|
||||
System.out.println("======結果=====");
|
||||
System.out.println(result);
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,13 @@ import com.example.demo.persistence.Q1Dao;
|
||||
|
||||
@Service
|
||||
public class Q1Service {
|
||||
@Autowired
|
||||
private Q1Dao q1Dao;
|
||||
public Q1Entity processService(String mailAdress, String password) {
|
||||
return q1Dao.createEntity(mailAdress,password);
|
||||
}
|
||||
|
||||
//Q1ServiceがQ1Daoを使いたい→Q1Daoを渡しておくね
|
||||
@Autowired
|
||||
Q1Dao dao;
|
||||
|
||||
public Q1Entity getUserData(String mailAddress, String password) {
|
||||
|
||||
return dao.findData(mailAddress, password);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user