Q2 (HTML) Done
This commit is contained in:
@@ -1,42 +1,112 @@
|
|||||||
package com.example.demo.controller;
|
package com.example.demo.controller;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
|
import com.example.demo.entity.Employee;
|
||||||
|
import com.example.demo.form.EmployeeForm;
|
||||||
|
import com.example.demo.form.LoginForm;
|
||||||
|
import com.example.demo.service.EmployeeService;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class MainController {
|
public class MainController {
|
||||||
@RequestMapping(value = "/",method = RequestMethod.GET)
|
|
||||||
public String loin() {
|
|
||||||
return"login";
|
|
||||||
}
|
|
||||||
@RequestMapping(value = "/doLogin",method = RequestMethod.POST)
|
|
||||||
public String doLoin() {
|
|
||||||
return"menu";
|
|
||||||
}
|
|
||||||
@RequestMapping(value = "/logout",method = RequestMethod.POST)
|
|
||||||
public String logout() {
|
|
||||||
return "login";
|
|
||||||
}
|
|
||||||
@RequestMapping(value = "/select",method = RequestMethod.POST)
|
|
||||||
public String select() {
|
|
||||||
return "select";
|
|
||||||
}
|
|
||||||
@RequestMapping(value = "/back",method = RequestMethod.POST)
|
|
||||||
public String back() {
|
|
||||||
return "menu";
|
|
||||||
}
|
|
||||||
@RequestMapping(value = "/insert",method = RequestMethod.POST)
|
|
||||||
public String insert() {
|
|
||||||
return "insert";
|
|
||||||
}
|
|
||||||
@RequestMapping(value = "/update",method = RequestMethod.POST)
|
|
||||||
public String update() {
|
|
||||||
return "update";
|
|
||||||
}
|
|
||||||
@RequestMapping(value = "/delete",method = RequestMethod.POST)
|
|
||||||
public String delete() {
|
|
||||||
return "delete";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private HttpSession session;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EmployeeService employeeService;
|
||||||
|
|
||||||
|
@GetMapping("/")
|
||||||
|
public String login(Model model) {
|
||||||
|
model.addAttribute("loginForm", new LoginForm());
|
||||||
|
return "login";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/doLogin")
|
||||||
|
public String doLogin(@ModelAttribute LoginForm form, Model model) {
|
||||||
|
var employeeOpt = employeeService.login(form.getMail(), form.getPass());
|
||||||
|
if (employeeOpt.isPresent()) {
|
||||||
|
session.setAttribute("login_emp", employeeOpt.get());
|
||||||
|
return "menu";
|
||||||
|
}
|
||||||
|
model.addAttribute("error", "メールアドレスまたはパスワードが違います");
|
||||||
|
return "login";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/logout")
|
||||||
|
public String logout() {
|
||||||
|
session.invalidate(); // Session ကို ဖျက်ပစ်ခြင်း
|
||||||
|
return "redirect:/";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/back")
|
||||||
|
public String back() {
|
||||||
|
return "menu";
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- ရှာဖွေခြင်း (select) ---
|
||||||
|
@PostMapping("/select")
|
||||||
|
public String select(Model model) {
|
||||||
|
List<Employee> list = employeeService.getAllEmployee();
|
||||||
|
model.addAttribute("employeeList",list);
|
||||||
|
return "select";
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- သစ်ထည့်ခြင်း (insert) ---
|
||||||
|
@PostMapping("/insert")
|
||||||
|
public String insert(Model model) {
|
||||||
|
model.addAttribute("employeeForm", new EmployeeForm());
|
||||||
|
return "insert";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/insertConfirm")
|
||||||
|
public String insertConfirm(@ModelAttribute EmployeeForm form, Model model) {
|
||||||
|
model.addAttribute("employeeForm", form);
|
||||||
|
return "insertConfirm";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/insertResult")
|
||||||
|
public String insertResult(@ModelAttribute EmployeeForm form) {
|
||||||
|
// Form -> Entity သို့ ပြောင်းပြီး Save လုပျရပါမညျ
|
||||||
|
return "insertResult";
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- ပြင်ဆင်ခြင်း (update) ---
|
||||||
|
@PostMapping("/update")
|
||||||
|
public String update(Model model) {
|
||||||
|
model.addAttribute("employeeForm", new EmployeeForm());
|
||||||
|
return "update";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/updateConfirm")
|
||||||
|
public String updateConfirm(@ModelAttribute EmployeeForm form, Model model) {
|
||||||
|
model.addAttribute("employeeForm", form);
|
||||||
|
return "updateConfirm";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/updateResult")
|
||||||
|
public String updateResult(@ModelAttribute EmployeeForm form) {
|
||||||
|
return "updateResult";
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- ဖျက်ဆီးခြင်း (delete) ---
|
||||||
|
@PostMapping("/delete")
|
||||||
|
public String delete() {
|
||||||
|
return "delete";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/deleteResult")
|
||||||
|
public String deleteResult(Integer id) {
|
||||||
|
// employeeService.deleteById(id);
|
||||||
|
return "deleteResult";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.example.demo.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
@Data
|
||||||
|
@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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.example.demo.form;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class EmployeeForm {
|
||||||
|
|
||||||
|
private String nmEmp;
|
||||||
|
|
||||||
|
private String knEmp;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.example.demo.form;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class LoginForm {
|
||||||
|
private String mail;
|
||||||
|
private String pass;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.example.demo.repsitory;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import com.example.demo.entity.Employee;
|
||||||
|
|
||||||
|
public interface EmployeeRepository extends JpaRepository<Employee, Integer> {
|
||||||
|
Optional<Employee> findByMailAddressAndPassword(String mail, String pass);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.example.demo.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import jakarta.transaction.Transactional;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.example.demo.entity.Employee;
|
||||||
|
import com.example.demo.repsitory.EmployeeRepository;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional
|
||||||
|
public class EmployeeService {
|
||||||
|
@Autowired
|
||||||
|
private EmployeeRepository employeeRepository;
|
||||||
|
|
||||||
|
// Login စစ်ဆေးခြင်း
|
||||||
|
public Optional<Employee> login(String mail, String pass) {
|
||||||
|
return employeeRepository.findByMailAddressAndPassword(mail, pass);
|
||||||
|
}
|
||||||
|
// အချက်အလက်အားလုံး ရှာဖွေခြင်း
|
||||||
|
public List<Employee> getAllEmployee() {
|
||||||
|
return employeeRepository.findAll();
|
||||||
|
}
|
||||||
|
// အချက်အလက် သိမ်းဆည်းခြင်း / ပြင်ဆင်ခြင်း
|
||||||
|
public Employee save(Employee employee) {
|
||||||
|
return employeeRepository.save(employee);
|
||||||
|
}
|
||||||
|
// အချက်အလက် ဖျက်ဆီးခြင်း
|
||||||
|
public void deleteById(Integer id) {
|
||||||
|
employeeRepository.deleteById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,20 +1,25 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html xmlns:th="http://www.thymeleaf.org">
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>削除ページ</title>
|
<title>削除ページ</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<h3> 削除</h3>
|
<h3>削除</h3>
|
||||||
<form action="logout" method="post">
|
<form action="logout" method="post">
|
||||||
<input type="submit" value="ログアウト">
|
<input type="submit" value="ログアウト">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<!-- ID တစ်ခုတည်း ရိုက်ထည့်ရန် Form -->
|
||||||
|
<form action="deleteResult" method="post">
|
||||||
|
<div><label>id: <input type="number" name="idEmployee"></label></div>
|
||||||
|
<br>
|
||||||
|
<input type="submit" value="削除">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<br>
|
||||||
<form action="back" method="post">
|
<form action="back" method="post">
|
||||||
<input type="submit" value="戻る">
|
<input type="submit" value="戻る">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
20
Spring-HTML/src/main/resources/templates/deleteResult.html
Normal file
20
Spring-HTML/src/main/resources/templates/deleteResult.html
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>削除確認ページ</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h3> 削除完了しました。</h3>
|
||||||
|
<form action="logout" method="post">
|
||||||
|
<input type="submit" value="ログアウト">
|
||||||
|
</form>
|
||||||
|
<form action="back" method="post">
|
||||||
|
<input type="submit" value="戻る">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -11,6 +11,17 @@
|
|||||||
<form action="logout" method="post">
|
<form action="logout" method="post">
|
||||||
<input type="submit" value="ログアウト">
|
<input type="submit" value="ログアウト">
|
||||||
</form>
|
</form>
|
||||||
|
<!-- Input Form များ -->
|
||||||
|
<form action="insertConfirm" method="post">
|
||||||
|
<div><label>name: <input type="text" name="nmEmp"></label></div>
|
||||||
|
<div><label>kana: <input type="text" name="knEmp"></label></div>
|
||||||
|
<div><label>mail: <input type="email" name="mail"></label></div>
|
||||||
|
<div><label>pass: <input type="password" name="pass"></label></div>
|
||||||
|
<div><label>id_dep: <input type="number" name="idDepartment"></label></div>
|
||||||
|
<br>
|
||||||
|
<input type="submit" value="登録">
|
||||||
|
</form>
|
||||||
|
<br>
|
||||||
<form action="back" method="post">
|
<form action="back" method="post">
|
||||||
<input type="submit" value="戻る">
|
<input type="submit" value="戻る">
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
17
Spring-HTML/src/main/resources/templates/insertConfirm.html
Normal file
17
Spring-HTML/src/main/resources/templates/insertConfirm.html
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>insert Result</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h3>登録完了しました。</h3>
|
||||||
|
<form action="logout" method="post">
|
||||||
|
<input type="submit" value="ログアウト">
|
||||||
|
</form>
|
||||||
|
<form action="back" method="post">
|
||||||
|
<input type="submit" value="戻る">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<form action="doLogin" method="post">
|
<form action="doLogin" method="post">
|
||||||
|
<input type="email"name="mail"placeholder="メールアドレス">
|
||||||
|
<input type="password"name="pass"placeholder="パスワード">
|
||||||
<input type="submit" value="ログイン">
|
<input type="submit" value="ログイン">
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -21,8 +21,14 @@
|
|||||||
</form>
|
</form>
|
||||||
<form action="delete" method="post">
|
<form action="delete" method="post">
|
||||||
<input type="submit" value="削除">
|
<input type="submit" value="削除">
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<!-- ログイン者情報の表示(キー名を login_emp に修正) -->
|
||||||
|
<div th:if="${session.login_emp != null}">
|
||||||
|
<span th:text="|ログイン者:${session.login_emp.nmEmployee}|"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@@ -6,15 +6,32 @@
|
|||||||
<title>検索ページ</title>
|
<title>検索ページ</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<brbody>
|
||||||
<h3> 検索</h3>
|
<h3> 検索</h3>
|
||||||
<form action="logout" method="post">
|
<form action="logout" method="post">
|
||||||
<input type="submit" value="ログアウト">
|
<input type="submit" value="ログアウト">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<!-- ဇယားဖြင့် အချက်အလက်များ ပြသခြင်း -->
|
||||||
|
<table border="1">
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>名前</th>
|
||||||
|
<th>カナ</th>
|
||||||
|
<th>メールアドレス</th>
|
||||||
|
</tr>
|
||||||
|
<tr th:each="emp : ${employeeList}">
|
||||||
|
<td th:text="${emp.idEmployee}"></td>
|
||||||
|
<td th:text="${emp.nmEmployee}"></td>
|
||||||
|
<td th:text="${emp.knEmployee}"></td>
|
||||||
|
<td th:text="${emp.mailAddress}"></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
<form action="back" method="post">
|
<form action="back" method="post">
|
||||||
<input type="submit" value="戻る">
|
<input type="submit" value="戻る">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@@ -11,6 +11,18 @@
|
|||||||
<form action="logout" method="post">
|
<form action="logout" method="post">
|
||||||
<input type="submit" value="ログアウト">
|
<input type="submit" value="ログアウト">
|
||||||
</form>
|
</form>
|
||||||
|
<!-- Input Form များ -->
|
||||||
|
<form action="updateConfirm" method="post">
|
||||||
|
<div><label>id: <input type="number" name="idEmployee"></label></div>
|
||||||
|
<div><label>name: <input type="text" name="nmEmp"></label></div>
|
||||||
|
<div><label>kana: <input type="text" name="knEmp"></label></div>
|
||||||
|
<div><label>mail: <input type="email" name="mail"></label></div>
|
||||||
|
<div><label>pass: <input type="password" name="pass"></label></div>
|
||||||
|
<div><label>id_dep: <input type="number" name="idDepartment"></label></div>
|
||||||
|
<br>
|
||||||
|
<input type="submit" value="更新">
|
||||||
|
</form>
|
||||||
|
<br>
|
||||||
<form action="back" method="post">
|
<form action="back" method="post">
|
||||||
<input type="submit" value="戻る">
|
<input type="submit" value="戻る">
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
21
Spring-HTML/src/main/resources/templates/updateConfirm.html
Normal file
21
Spring-HTML/src/main/resources/templates/updateConfirm.html
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>更新ページ</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h3> 更新完了しました。</h3>
|
||||||
|
<form action="logout" method="post">
|
||||||
|
<input type="submit" value="ログアウト">
|
||||||
|
</form>
|
||||||
|
<br>
|
||||||
|
<form action="back" method="post">
|
||||||
|
<input type="submit" value="戻る">
|
||||||
|
</form>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user