This commit is contained in:
s-sakiyama
2026-10-06 16:48:54 +09:00
parent 0a7c131a9b
commit 85e95d5104
7 changed files with 189 additions and 6 deletions

View File

@@ -3,22 +3,26 @@ 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;
import com.example.demo.presentation.Q3View;
@SpringBootApplication
@Import(Q2Config.class)
//@Import(Q2Config.class)//Q2
public class SpringExampleApplication {
public static void main(String[] args) {
//Q1
// ConfigurableApplicationContext context = SpringApplication.run(SpringExampleApplication.class, args);
// Q1View view = context.getBean(Q1View.class);
// view.mailpassPrint();
//Q2
// ConfigurableApplicationContext context = SpringApplication.run(SpringExampleApplication.class, args);
// Q2View view = context.getBean(Q2View.class);
// view.mailpassPrint();
//Q3
ConfigurableApplicationContext context = SpringApplication.run(SpringExampleApplication.class, args);
Q2View view = context.getBean(Q2View.class);
view.mailpassPrint();
Q3View view = context.getBean(Q3View.class);
view.usernameSearch();
}

View File

@@ -0,0 +1,26 @@
package com.example.demo.application;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.example.demo.logic.Q3Logic;
import com.example.demo.service.Q3Service;
@Controller
public class Q3Controller {
@Autowired
Q3Service ser;
@Autowired
Q3Logic log;
public String usernameSearch(String mail, String pass) {
if (mail.length() > 256) {
return "メールアドレスもしくはパスワードが不正です";
}
if (pass.length() < 8) {
return "メールアドレスもしくはパスワードが不正です";
}
return log.match(ser.allDateGet(), mail, pass);
}
}

View File

@@ -0,0 +1,76 @@
package com.example.demo.domain;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Entity
@Table(name = "employee")
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_employee", nullable = false)
private Integer idEmployee;
@Column(name = "nm_employee", nullable = false)
private String nmEmployee;
@Column(name = "kn_employee", nullable = false)
private String knEmployee;
@Column(name = "mail_address", nullable = false)
private String mailAddress;
@Column(name = "password", nullable = false)
private String password;
@Column(name = "id_department", nullable = false)
private Integer idDepartment;
public Integer getIdEmployee() {
return idEmployee;
}
public void setIdEmployee(Integer idEmployee) {
this.idEmployee = idEmployee;
}
public String getNmEmployee() {
return nmEmployee;
}
public void setNmEmployee(String nmEmployee) {
this.nmEmployee = nmEmployee;
}
public String getKnEmployee() {
return knEmployee;
}
public void setKnEmployee(String knEmployee) {
this.knEmployee = knEmployee;
}
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;
}
public Integer getIdDepartment() {
return idDepartment;
}
public void setIdDepartment(Integer idDepartment) {
this.idDepartment = idDepartment;
}
}

View File

@@ -0,0 +1,22 @@
package com.example.demo.logic;
import java.util.List;
import org.springframework.stereotype.Component;
import com.example.demo.domain.Employee;
@Component
public class Q3Logic {
public String match(List<Employee> list, String mail, String pass) {
for (Employee emp : list) {
if (emp.getMailAddress().equals(mail) && emp.getPassword().equals(pass)) {
return emp.getNmEmployee();
}
}
return "該当のデータが存在しません。";
}
}

View File

@@ -0,0 +1,11 @@
package com.example.demo.persistence;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.example.demo.domain.Employee;
@Repository
public interface EmployeeRepository extends JpaRepository<Employee, Integer> {
}

View File

@@ -0,0 +1,25 @@
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.Q3Controller;
@Component
public class Q3View {
@Autowired
Q3Controller con;
Scanner scan = new Scanner(System.in);
public void usernameSearch() {
//入力
System.out.println("メールアドレスを入力");
String mail = scan.nextLine().strip();
System.out.println("パスワードを入力");
String pass = scan.nextLine().strip();
System.out.println(con.usernameSearch(mail, pass));
}
}

View File

@@ -0,0 +1,19 @@
package com.example.demo.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.demo.domain.Employee;
import com.example.demo.persistence.EmployeeRepository;
@Service
public class Q3Service {
@Autowired
EmployeeRepository empre;
public List<Employee> allDateGet() {
return empre.findAll();
}
}