<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      培訓管理子系統開發1

      整個項目預期的任務量 (任務量 = 所有工作的預期時間10天)和 目前已經花的時間 (所有記錄的 ‘已經花費的時間’1天),還剩余的時間(所有工作的 ‘剩余時間’9天)

      實現管理員和員工注冊登錄功能




      代碼實現:

      package com.example.training.entity;
      
      import javax.persistence.*;
      
      @Entity
      @Table(name = "user")
      public class User {
          // 內部枚舉定義
          public enum Role {
              ADMIN, EMPLOYEE
          }
      
          @Id
          @GeneratedValue(strategy = GenerationType.IDENTITY)
          private Integer id;
      
          @Column(unique = true)
          private String name;
      
          private String password;
      
          @Enumerated(EnumType.STRING)
          private Role role;
      
          // 構造方法
          public User() {}
      
          public User(String name, String password, Role role) {
              this.name = name;
              this.password = password;
              this.role = role;
          }
      
          // Getter和Setter
          public Integer getId() {
              return id;
          }
      
          public void setId(Integer id) {
              this.id = id;
          }
      
          public String getName() {
              return name;
          }
      
          public void setName(String name) {
              this.name = name;
          }
      
          public String getPassword() {
              return password;
          }
      
          public void setPassword(String password) {
              this.password = password;
          }
      
          public Role getRole() {
              return role;
          }
      
          public void setRole(Role role) {
              this.role = role;
          }
      }
      package com.example.training.service;
      
      import com.example.training.entity.User;
      import com.example.training.repository.UserRepository;
      import org.springframework.stereotype.Service;
      
      @Service
      public class UserService {
          private final UserRepository userRepository;
      
          public UserService(UserRepository userRepository) {
              this.userRepository = userRepository;
          }
      
          public User register(String name, String password,User.Role role) {
              if (userRepository.findByName(name) != null) {
                  throw new RuntimeException("用戶名已存在");
              }
              User user = new User();
              user.setName(name);
              user.setPassword(password);
              user.setRole(role);
              return userRepository.save(user);
          }
      
          public User login(String name, String password) {
              User user = userRepository.findByName(name);
              if (user == null || !user.getPassword().equals(password)) {
                  throw new RuntimeException("用戶名或密碼錯誤");
              }
              return user;
          }
      }
      package com.example.training.controller;
      
      import com.example.training.entity.User;
      import com.example.training.service.UserService;
      import org.springframework.stereotype.Controller;
      import org.springframework.ui.Model;
      import org.springframework.web.bind.annotation.GetMapping;
      import org.springframework.web.bind.annotation.PostMapping;
      import org.springframework.web.bind.annotation.RequestParam;
      import javax.servlet.http.HttpSession;
      
      @Controller
      public class AuthController {
          private final UserService userService;
      
          public AuthController(UserService userService) {
              this.userService = userService;
          }
      
          @GetMapping("/")
          public String home() {
              return "redirect:/login";
          }
      
          @GetMapping("/login")
          public String showLoginForm() {
              return "login";
          }
      
          @PostMapping("/login")
          public String login(@RequestParam String name,
                              @RequestParam String password,
                              HttpSession session,
                              Model model) {
              try {
                  User user = userService.login(name, password);
                  session.setAttribute("user", user);
      
                  // 根據角色跳轉不同頁面
                  if (user.getRole() == User.Role.ADMIN) {
                      return "redirect:/admin/dashboard";
                  }
                  // 普通員工跳轉到工作臺頁面(需要后續開發)
                  return "redirect:/employee/dashboard";
              } catch (Exception e) {
                  model.addAttribute("error", e.getMessage());
                  return "login";
              }
          }
      
          @GetMapping("/register")
          public String showRegisterForm() {
              return "register";
          }
      
          @PostMapping("/register")
          public String register(@RequestParam String name,
                                 @RequestParam String password,
                                 @RequestParam User.Role role,
                                 Model model) {
              try {
                  userService.register(name, password, role);
                  model.addAttribute("message", "注冊成功,請登錄!");
                  return "redirect:/login";
              } catch (Exception e) {
                  model.addAttribute("error", e.getMessage());
                  return "register";
              }
          }
      
          @GetMapping("/logout")
          public String logout(HttpSession session) {
              session.invalidate();
              return "redirect:/login";
          }
      }
      <!DOCTYPE html>
      <html xmlns:th="http://www.thymeleaf.org">
      <head>
          <title>登錄</title>
          <meta name="viewport" content="width=device-width, initial-scale=1">
          <style>
              body {
                  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
                  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
                  margin: 0;
                  min-height: 100vh;
                  display: flex;
                  justify-content: center;
                  align-items: center;
              }
      
              .login-container {
                  background: rgba(255, 255, 255, 0.95);
                  padding: 2.5rem;
                  border-radius: 12px;
                  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
                  width: 100%;
                  max-width: 400px;
                  transition: transform 0.3s ease;
              }
      
              h2 {
                  color: #1e3c72;
                  text-align: center;
                  margin-bottom: 2rem;
                  font-size: 1.8rem;
                  border-bottom: 2px solid #1e3c72;
                  padding-bottom: 1rem;
              }
      
              form {
                  display: flex;
                  flex-direction: column;
                  gap: 1.2rem;
              }
      
              input {
                  padding: 12px 15px;
                  border: 2px solid #e0e0e0;
                  border-radius: 6px;
                  font-size: 1rem;
                  transition: border-color 0.3s ease;
              }
      
              input:focus {
                  outline: none;
                  border-color: #1e3c72;
              }
      
              button {
                  background: #1e3c72;
                  color: white;
                  padding: 12px;
                  border: none;
                  border-radius: 6px;
                  font-size: 1rem;
                  cursor: pointer;
                  transition: background 0.3s ease;
              }
      
              button:hover {
                  background: #2a5298;
              }
      
              .register-link {
                  text-align: center;
                  margin-top: 1.5rem;
                  color: #1e3c72;
              }
      
              .register-link a {
                  color: #2a5298;
                  text-decoration: none;
                  font-weight: 600;
                  transition: color 0.3s ease;
              }
      
              .register-link a:hover {
                  color: #1e3c72;
                  text-decoration: underline;
              }
      
              .error-message {
                  background: #ffebee;
                  color: #c62828;
                  padding: 12px;
                  border-radius: 6px;
                  margin-bottom: 1.5rem;
                  text-align: center;
                  border: 1px solid #ffcdd2;
              }
          </style>
      </head>
      <body>
      <div class="login-container">
          <h2>培訓管理子系統</h2>
      
          <!-- 顯示錯誤信息 -->
          <div th:if="${error}" class="error-message" th:text="${error}"></div>
      
          <form th:action="@{/login}" method="post">
              <input type="text" name="name" placeholder="用戶名" required>
              <input type="password" name="password" placeholder="密碼" required>
              <button type="submit">立即登錄</button>
          </form>
      
          <div class="register-link">
              <p>沒有賬號?<a th:href="@{/register}">立即注冊</a></p>
          </div>
      </div>
      </body>
      </html>
      
      <!DOCTYPE html>
      <html xmlns:th="http://www.thymeleaf.org">
      <head>
          <title>注冊</title>
          <meta name="viewport" content="width=device-width, initial-scale=1">
          <style>
              body {
                  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
                  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
                  margin: 0;
                  min-height: 100vh;
                  display: flex;
                  justify-content: center;
                  align-items: center;
              }
      
              .register-container {
                  background: rgba(255, 255, 255, 0.95);
                  padding: 2.5rem;
                  border-radius: 12px;
                  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
                  width: 100%;
                  max-width: 400px;
              }
      
              h2 {
                  color: #1e3c72;
                  text-align: center;
                  margin-bottom: 1.5rem;
                  font-size: 1.8rem;
                  border-bottom: 2px solid #1e3c72;
                  padding-bottom: 1rem;
              }
      
              form {
                  display: flex;
                  flex-direction: column;
                  gap: 1.5rem;
              }
      
              .form-group {
                  display: flex;
                  flex-direction: column;
                  gap: 0.5rem;
              }
      
              label {
                  color: #1e3c72;
                  font-weight: 600;
                  font-size: 0.9rem;
              }
      
              input, select {
                  padding: 12px 15px;
                  border: 2px solid #e0e0e0;
                  border-radius: 6px;
                  font-size: 1rem;
                  transition: all 0.3s ease;
              }
      
              input:focus, select:focus {
                  outline: none;
                  border-color: #1e3c72;
                  box-shadow: 0 0 5px rgba(30, 60, 114, 0.2);
              }
      
              button {
                  background: #1e3c72;
                  color: white;
                  padding: 12px;
                  border: none;
                  border-radius: 6px;
                  font-size: 1rem;
                  cursor: pointer;
                  transition: background 0.3s ease;
                  margin-top: 1rem;
              }
      
              button:hover {
                  background: #2a5298;
              }
      
              .login-link {
                  text-align: center;
                  margin-top: 1.5rem;
              }
      
              .login-link a {
                  color: #2a5298;
                  text-decoration: none;
                  font-weight: 600;
                  transition: color 0.3s ease;
              }
      
              .login-link a:hover {
                  color: #1e3c72;
                  text-decoration: underline;
              }
      
              .alert {
                  padding: 12px;
                  border-radius: 6px;
                  margin-bottom: 1.5rem;
                  text-align: center;
                  border: 1px solid transparent;
              }
      
              .alert-success {
                  background: #e8f5e9;
                  color: #2e7d32;
                  border-color: #c8e6c9;
              }
      
              .alert-error {
                  background: #ffebee;
                  color: #c62828;
                  border-color: #ffcdd2;
              }
          </style>
      </head>
      <body>
      <div class="register-container">
          <h2>培訓管理子系統</h2>
      
          <!-- 消息提示 -->
          <div th:if="${message}" class="alert alert-success" th:text="${message}"></div>
          <div th:if="${error}" class="alert alert-error" th:text="${error}"></div>
      
          <form th:action="@{/register}" method="post">
              <div class="form-group">
                  <label>用戶名:</label>
                  <input type="text" name="name" required>
              </div>
      
              <div class="form-group">
                  <label>密碼:</label>
                  <input type="password" name="password" required>
              </div>
      
              <div class="form-group">
                  <label>身份:</label>
                  <select name="role">
                      <option value="ADMIN">管理員</option>
                      <option value="EMPLOYEE">員工</option>
                  </select>
              </div>
      
              <button type="submit">立即注冊</button>
          </form>
      
          <div class="login-link">
              <a th:href="@{/login}">已有賬號?去登錄</a>
          </div>
      </div>
      </body>package com.example.training.entity;
      
      import javax.persistence.*;
      
      @Entity
      @Table(name = "user")
      public class User {
          // 內部枚舉定義
          public enum Role {
              ADMIN, EMPLOYEE
          }
      
          @Id
          @GeneratedValue(strategy = GenerationType.IDENTITY)
          private Integer id;
      
          @Column(unique = true)
          private String name;
      
          private String password;
      
          @Enumerated(EnumType.STRING)
          private Role role;
      
          // 構造方法
          public User() {}
      
          public User(String name, String password, Role role) {
              this.name = name;
              this.password = password;
              this.role = role;
          }
      
          // Getter和Setter
          public Integer getId() {
              return id;
          }
      
          public void setId(Integer id) {
              this.id = id;
          }
      
          public String getName() {
              return name;
          }
      
          public void setName(String name) {
              this.name = name;
          }
      
          public String getPassword() {
              return password;
          }
      
          public void setPassword(String password) {
              this.password = password;
          }
      
          public Role getRole() {
              return role;
          }
      
          public void setRole(Role role) {
              this.role = role;
          }
      }
      package com.example.training.service;
      
      import com.example.training.entity.User;
      import com.example.training.repository.UserRepository;
      import org.springframework.stereotype.Service;
      
      @Service
      public class UserService {
          private final UserRepository userRepository;
      
          public UserService(UserRepository userRepository) {
              this.userRepository = userRepository;
          }
      
          public User register(String name, String password,User.Role role) {
              if (userRepository.findByName(name) != null) {
                  throw new RuntimeException("用戶名已存在");
              }
              User user = new User();
              user.setName(name);
              user.setPassword(password);
              user.setRole(role);
              return userRepository.save(user);
          }
      
          public User login(String name, String password) {
              User user = userRepository.findByName(name);
              if (user == null || !user.getPassword().equals(password)) {
                  throw new RuntimeException("用戶名或密碼錯誤");
              }
              return user;
          }
      }
      package com.example.training.controller;
      
      import com.example.training.entity.User;
      import com.example.training.service.UserService;
      import org.springframework.stereotype.Controller;
      import org.springframework.ui.Model;
      import org.springframework.web.bind.annotation.GetMapping;
      import org.springframework.web.bind.annotation.PostMapping;
      import org.springframework.web.bind.annotation.RequestParam;
      import javax.servlet.http.HttpSession;
      
      @Controller
      public class AuthController {
          private final UserService userService;
      
          public AuthController(UserService userService) {
              this.userService = userService;
          }
      
          @GetMapping("/")
          public String home() {
              return "redirect:/login";
          }
      
          @GetMapping("/login")
          public String showLoginForm() {
              return "login";
          }
      
          @PostMapping("/login")
          public String login(@RequestParam String name,
                              @RequestParam String password,
                              HttpSession session,
                              Model model) {
              try {
                  User user = userService.login(name, password);
                  session.setAttribute("user", user);
      
                  // 根據角色跳轉不同頁面
                  if (user.getRole() == User.Role.ADMIN) {
                      return "redirect:/admin/dashboard";
                  }
                  // 普通員工跳轉到工作臺頁面(需要后續開發)
                  return "redirect:/employee/dashboard";
              } catch (Exception e) {
                  model.addAttribute("error", e.getMessage());
                  return "login";
              }
          }
      
          @GetMapping("/register")
          public String showRegisterForm() {
              return "register";
          }
      
          @PostMapping("/register")
          public String register(@RequestParam String name,
                                 @RequestParam String password,
                                 @RequestParam User.Role role,
                                 Model model) {
              try {
                  userService.register(name, password, role);
                  model.addAttribute("message", "注冊成功,請登錄!");
                  return "redirect:/login";
              } catch (Exception e) {
                  model.addAttribute("error", e.getMessage());
                  return "register";
              }
          }
      
          @GetMapping("/logout")
          public String logout(HttpSession session) {
              session.invalidate();
              return "redirect:/login";
          }
      }
      <!DOCTYPE html>
      <html xmlns:th="http://www.thymeleaf.org">
      <head>
          <title>登錄</title>
          <meta name="viewport" content="width=device-width, initial-scale=1">
          <style>
              body {
                  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
                  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
                  margin: 0;
                  min-height: 100vh;
                  display: flex;
                  justify-content: center;
                  align-items: center;
              }
      
              .login-container {
                  background: rgba(255, 255, 255, 0.95);
                  padding: 2.5rem;
                  border-radius: 12px;
                  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
                  width: 100%;
                  max-width: 400px;
                  transition: transform 0.3s ease;
              }
      
              h2 {
                  color: #1e3c72;
                  text-align: center;
                  margin-bottom: 2rem;
                  font-size: 1.8rem;
                  border-bottom: 2px solid #1e3c72;
                  padding-bottom: 1rem;
              }
      
              form {
                  display: flex;
                  flex-direction: column;
                  gap: 1.2rem;
              }
      
              input {
                  padding: 12px 15px;
                  border: 2px solid #e0e0e0;
                  border-radius: 6px;
                  font-size: 1rem;
                  transition: border-color 0.3s ease;
              }
      
              input:focus {
                  outline: none;
                  border-color: #1e3c72;
              }
      
              button {
                  background: #1e3c72;
                  color: white;
                  padding: 12px;
                  border: none;
                  border-radius: 6px;
                  font-size: 1rem;
                  cursor: pointer;
                  transition: background 0.3s ease;
              }
      
              button:hover {
                  background: #2a5298;
              }
      
              .register-link {
                  text-align: center;
                  margin-top: 1.5rem;
                  color: #1e3c72;
              }
      
              .register-link a {
                  color: #2a5298;
                  text-decoration: none;
                  font-weight: 600;
                  transition: color 0.3s ease;
              }
      
              .register-link a:hover {
                  color: #1e3c72;
                  text-decoration: underline;
              }
      
              .error-message {
                  background: #ffebee;
                  color: #c62828;
                  padding: 12px;
                  border-radius: 6px;
                  margin-bottom: 1.5rem;
                  text-align: center;
                  border: 1px solid #ffcdd2;
              }
          </style>
      </head>
      <body>
      <div class="login-container">
          <h2>培訓管理子系統</h2>
      
          <!-- 顯示錯誤信息 -->
          <div th:if="${error}" class="error-message" th:text="${error}"></div>
      
          <form th:action="@{/login}" method="post">
              <input type="text" name="name" placeholder="用戶名" required>
              <input type="password" name="password" placeholder="密碼" required>
              <button type="submit">立即登錄</button>
          </form>
      
          <div class="register-link">
              <p>沒有賬號?<a th:href="@{/register}">立即注冊</a></p>
          </div>
      </div>
      </body>
      </html>
      
      <!DOCTYPE html>
      <html xmlns:th="http://www.thymeleaf.org">
      <head>
          <title>注冊</title>
          <meta name="viewport" content="width=device-width, initial-scale=1">
          <style>
              body {
                  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
                  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
                  margin: 0;
                  min-height: 100vh;
                  display: flex;
                  justify-content: center;
                  align-items: center;
              }
      
              .register-container {
                  background: rgba(255, 255, 255, 0.95);
                  padding: 2.5rem;
                  border-radius: 12px;
                  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
                  width: 100%;
                  max-width: 400px;
              }
      
              h2 {
                  color: #1e3c72;
                  text-align: center;
                  margin-bottom: 1.5rem;
                  font-size: 1.8rem;
                  border-bottom: 2px solid #1e3c72;
                  padding-bottom: 1rem;
              }
      
              form {
                  display: flex;
                  flex-direction: column;
                  gap: 1.5rem;
              }
      
              .form-group {
                  display: flex;
                  flex-direction: column;
                  gap: 0.5rem;
              }
      
              label {
                  color: #1e3c72;
                  font-weight: 600;
                  font-size: 0.9rem;
              }
      
              input, select {
                  padding: 12px 15px;
                  border: 2px solid #e0e0e0;
                  border-radius: 6px;
                  font-size: 1rem;
                  transition: all 0.3s ease;
              }
      
              input:focus, select:focus {
                  outline: none;
                  border-color: #1e3c72;
                  box-shadow: 0 0 5px rgba(30, 60, 114, 0.2);
              }
      
              button {
                  background: #1e3c72;
                  color: white;
                  padding: 12px;
                  border: none;
                  border-radius: 6px;
                  font-size: 1rem;
                  cursor: pointer;
                  transition: background 0.3s ease;
                  margin-top: 1rem;
              }
      
              button:hover {
                  background: #2a5298;
              }
      
              .login-link {
                  text-align: center;
                  margin-top: 1.5rem;
              }
      
              .login-link a {
                  color: #2a5298;
                  text-decoration: none;
                  font-weight: 600;
                  transition: color 0.3s ease;
              }
      
              .login-link a:hover {
                  color: #1e3c72;
                  text-decoration: underline;
              }
      
              .alert {
                  padding: 12px;
                  border-radius: 6px;
                  margin-bottom: 1.5rem;
                  text-align: center;
                  border: 1px solid transparent;
              }
      
              .alert-success {
                  background: #e8f5e9;
                  color: #2e7d32;
                  border-color: #c8e6c9;
              }
      
              .alert-error {
                  background: #ffebee;
                  color: #c62828;
                  border-color: #ffcdd2;
              }
          </style>
      </head>
      <body>
      <div class="register-container">
          <h2>培訓管理子系統</h2>
      
          <!-- 消息提示 -->
          <div th:if="${message}" class="alert alert-success" th:text="${message}"></div>
          <div th:if="${error}" class="alert alert-error" th:text="${error}"></div>
      
          <form th:action="@{/register}" method="post">
              <div class="form-group">
                  <label>用戶名:</label>
                  <input type="text" name="name" required>
              </div>
      
              <div class="form-group">
                  <label>密碼:</label>
                  <input type="password" name="password" required>
              </div>
      
              <div class="form-group">
                  <label>身份:</label>
                  <select name="role">
                      <option value="ADMIN">管理員</option>
                      <option value="EMPLOYEE">員工</option>
                  </select>
              </div>
      
              <button type="submit">立即注冊</button>
          </form>
      
          <div class="login-link">
              <a th:href="@{/login}">已有賬號?去登錄</a>
          </div>
      </div>
      </body>
      </html>
      </html>
      
      posted @ 2025-04-15 15:29  霸王雞  閱讀(11)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 97香蕉碰碰人妻国产欧美| 国产精品久久久一区二区三区| 高清无打码一区二区三区| 男人的天堂av社区在线| 粉嫩av国产一区二区三区| 国产一区二区三区在线观看免费| 丁香婷婷色综合激情五月| 无码一区二区三区av在线播放| 欧美精品一区二区在线观看播放| 国产蜜臀视频一区二区三区| 免费的特黄特色大片| 天堂网亚洲综合在线| 玩弄少妇人妻| 亚洲夜夜欢一区二区三区| 亚洲高潮喷水无码AV电影| 国语精品自产拍在线观看网站| 国内精品久久人妻无码妲| 欧美日韩精品一区二区视频| 国产精品伊人久久综合网| 欧美日韩一区二区三区视频播放| 日韩精品一区二区三区不卡| 国产精品中文字幕一区| 国产高清在线精品一区APP| 免费无码一区二区三区蜜桃| 这里只有精品在线播放| 国产一区二区在线激情往| 无码人妻丝袜在线视频| 2021亚洲国产精品无码| 扒开粉嫩的小缝隙喷白浆视频| 伊人狠狠色j香婷婷综合| 东京热人妻无码人av| 色五月丁香六月欧美综合| 精品亚洲男人一区二区三区| 欧美巨大极度另类| 色综合久久久久综合99| 深夜福利成人免费在线观看| 一本无码人妻在中文字幕免费| 不卡免费一区二区日韩av| 亚洲夂夂婷婷色拍ww47| 毛片大全真人在线| 日本熟妇乱一区二区三区|