update show username function

Signed-off-by: Chenx221 <chenx221@yandex.com>
This commit is contained in:
Chenx221 2023-06-11 12:27:37 +08:00
parent cc471c1478
commit 1ab1a4ad8a
26 changed files with 83 additions and 46 deletions

View File

@ -109,7 +109,8 @@
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg"></i>
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>

View File

@ -109,7 +109,8 @@
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg"></i>
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>

View File

@ -112,7 +112,8 @@
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg"></i>
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>
@ -298,7 +299,7 @@
<div class="row mb-2">
<div class="col-12">
<div class="form-outline">
<input type="text" id="typeText14" class="form-control"
<input type="text" id="typeText14" class="form-control" required
name="name"/>
<label class="form-label" for="typeText14">课程名 (必填)</label>
</div>
@ -307,7 +308,7 @@
<div class="row mb-2">
<div class="col-12">
<div class="form-outline">
<input type="text" id="typeText15" class="form-control"
<input type="text" id="typeText15" class="form-control" required
name="description"/>
<label class="form-label" for="typeText15">课程描述 (必填)</label>
</div>

View File

@ -96,7 +96,8 @@
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg"></i>
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>

View File

@ -109,7 +109,8 @@
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg"></i>
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>

View File

@ -108,7 +108,8 @@
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg"></i>
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>

View File

@ -110,7 +110,8 @@
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg"></i>
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>

View File

@ -109,7 +109,8 @@
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg"></i>
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>

View File

@ -112,7 +112,8 @@
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg"></i>
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>

View File

@ -1,5 +1,6 @@
package cyou.chenx221.controller;
import cyou.chenx221.helper.UsernameHelper;
import cyou.chenx221.pojo.Course;
import cyou.chenx221.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
@ -24,6 +25,10 @@ public class CourseController {
@GetMapping("/all")//课程信息查询不带条件
public String getAllCourses(Model model) {
String username = new UsernameHelper().getCurrentUsername();
if (username != null) {
model.addAttribute("username", username);
}
List<Course> courses = courseService.getAllCourses();
model.addAttribute("courses", courses);
return "courseList"; // 重定向到 dashboard 页面
@ -33,11 +38,16 @@ public class CourseController {
public String getInfoModv2(@RequestParam(value = "successMessage", required = false, defaultValue = "null") String successMessage,
@RequestParam(value = "errorMessage", required = false, defaultValue = "null") String errorMessage,
Model model) {
String username = new UsernameHelper().getCurrentUsername();
if (username != null) {
model.addAttribute("username", username);
}
List<Course> courses = courseService.getAllCourses();
model.addAttribute("courses", courses);
// 将消息添加到Model中
model.addAttribute("successMessage", successMessage);
model.addAttribute("errorMessage", errorMessage);
return "courseopv2";
}
@ -105,6 +115,10 @@ public class CourseController {
@RequestParam(value = "description", defaultValue = "null", required = false) String description,
@RequestParam(value = "id", defaultValue = "-1", required = false) int id,
Model model) {
String username = new UsernameHelper().getCurrentUsername();
if (username != null) {
model.addAttribute("username", username);
}
if (name.equals("null")) name = null;
if (description.equals("null")) description = null;
if (name == null && description == null && id <= 0) {

View File

@ -1,5 +1,6 @@
package cyou.chenx221.controller;
import cyou.chenx221.helper.UsernameHelper;
import cyou.chenx221.pojo.Student;
import cyou.chenx221.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
@ -26,13 +27,21 @@ public class StudentController {
@GetMapping("/all")//学生信息查询不带条件(排除removed的学生
public String getAllStudents(Model model) {
String username = new UsernameHelper().getCurrentUsername();
if (username != null) {
model.addAttribute("username", username);
}
List<Student> students = studentService.getAllStudents();
model.addAttribute("students", students);
return "studentList"; // 重定向到 dashboard 页面
}
@GetMapping("/queryinfo")//处理访问学生信息查询
public String getQueryInfo() {
public String getQueryInfo(Model model) {
String username = new UsernameHelper().getCurrentUsername();
if (username != null) {
model.addAttribute("username", username);
}
return "studentListQuery";
}
@ -44,6 +53,10 @@ public class StudentController {
@RequestParam(value = "phone", defaultValue = "null", required = false) String phone,
@RequestParam(value = "classes", defaultValue = "", required = false) List<String> classes,
Model model) {
String username = new UsernameHelper().getCurrentUsername();
if (username != null) {
model.addAttribute("username", username);
}
Date birthday = null;
if (!"null".equals(birthdayStr)) {
birthday = Date.valueOf(birthdayStr);
@ -84,6 +97,10 @@ public class StudentController {
public String getModStep1(@RequestParam(value = "successMessage", required = false, defaultValue = "null") String successMessage,
@RequestParam(value = "errorMessage", required = false, defaultValue = "null") String errorMessage,
Model model) {
String username = new UsernameHelper().getCurrentUsername();
if (username != null) {
model.addAttribute("username", username);
}
List<Student> students = studentService.getAllStudents();//和前面显示全部学生一样页面需要学生信息的显示
model.addAttribute("students", students);
// 将消息添加到Model中
@ -125,6 +142,10 @@ public class StudentController {
public String getInfoModv2(@RequestParam(value = "successMessage", required = false, defaultValue = "null") String successMessage,
@RequestParam(value = "errorMessage", required = false, defaultValue = "null") String errorMessage,
Model model) {
String username = new UsernameHelper().getCurrentUsername();
if (username != null) {
model.addAttribute("username", username);
}
List<Student> students = studentService.getAllStudents();//和前面显示全部学生一样页面需要学生信息的显示
model.addAttribute("students", students);
// 将消息添加到Model中

View File

@ -18,19 +18,6 @@ public class UserController {
@Autowired
private UserMapper userMapper;
// @RequestMapping(path = "/signin", method = {RequestMethod.GET, RequestMethod.POST}) //登录
// public String login(@RequestParam("username") String username, @RequestParam("password") String password, Model model) throws NoSuchAlgorithmException {
// User user = userMapper.getUserByUsername(username);
// Password pw = new Password(password);
//// System.out.println("username:" + username + " try to login with password: " + password + " encrypted-password:"+pw.getEncryptedPassword());
// if (user != null && user.getPassword().equals(pw.getEncryptedPassword())) {
// model.addAttribute("message", "登陆成功");
// return "redirect:/dashboard"; // 重定向到 dashboard 页面
// } else {
// model.addAttribute("errorMessage", "用户名或密码不正确,请重新输入。");
// return "login";
// }
// }
@RequestMapping(path = "/login", method = {RequestMethod.GET, RequestMethod.POST}) //登录
public String login() {
return "login";

View File

@ -1,33 +1,30 @@
package cyou.chenx221.controller;
import cyou.chenx221.helper.UsernameHelper;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class ViewController {
@RequestMapping(path = "/success", method = {RequestMethod.GET, RequestMethod.POST})
@RequestMapping(path = "/success", method = {RequestMethod.GET, RequestMethod.POST}) //弃用
public String success() {
return "views/success"; // 视图文件名
}
@RequestMapping(path = "/fail", method = {RequestMethod.GET, RequestMethod.POST})
@RequestMapping(path = "/fail", method = {RequestMethod.GET, RequestMethod.POST}) //弃用
public String fail() {
return "views/fail"; // 视图文件名
}
@RequestMapping(path = "/dashboard", method = {RequestMethod.GET, RequestMethod.POST})
public String showDashboard() {
public String showDashboard(Model model) {
String username = new UsernameHelper().getCurrentUsername();
if (username != null) {
model.addAttribute("username", username);
}
return "dashboard"; // 返回 dashboard 视图名
}
// @RequestMapping(path = "/studentList", method = {RequestMethod.GET, RequestMethod.POST})
// public String showstudentList() {
// return "studentList"; // 返回 studentList 视图名
// }
// @RequestMapping(path = "/studentListQuery", method = {RequestMethod.GET, RequestMethod.POST})
// public String showstudentListQuery() {
// return "studentListQuery"; // 返回 studentListQuery 视图名
// }
}

View File

@ -109,7 +109,8 @@
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg"></i>
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>

View File

@ -109,7 +109,8 @@
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg"></i>
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>

View File

@ -112,7 +112,8 @@
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg"></i>
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>

View File

@ -96,7 +96,8 @@
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg"></i>
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>

View File

@ -109,7 +109,8 @@
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg"></i>
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>

View File

@ -108,7 +108,8 @@
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg"></i>
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>

View File

@ -110,7 +110,8 @@
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg"></i>
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>

View File

@ -109,7 +109,8 @@
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg"></i>
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>

View File

@ -112,7 +112,8 @@
<div class="dropdown">
<a class="dropdown-toggle d-flex align-items-center hidden-arrow" href="#"
id="navbarDropdownMenuAvatar" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
<i class="fas fa-circle-user fa-lg"></i>
<i class="fas fa-circle-user fa-lg me-1"></i>
${username}
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuAvatar">
<li>