Section title
用户ID | 用户名 | 邮箱 | 性别 | 生日 | 部门ID | 部门名 | 操作 |
---|---|---|---|---|---|---|---|
[[${user.uName}]] | 编辑 |
package com.xuxu.pojo;
import java.util.Date;
/**
* 用户实体
*/
public class User {
private Integer uId;
private String uName;
private String email;
private Integer gender;
private Date birth;
private Department department;
public User() {
}
public User(Integer uId, String uName, String email, Integer gender, Date birth, Department department) {
this.uId = uId;
this.uName = uName;
this.email = email;
this.gender = gender;
this.birth = birth;
this.department = department;
}
public Integer getuId() {
return uId;
}
public void setuId(Integer uId) {
this.uId = uId;
}
public String getuName() {
return uName;
}
public void setuName(String uName) {
this.uName = uName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Integer getGender() {
return gender;
}
public void setGender(Integer gender) {
this.gender = gender;
}
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
}
package com.xuxu.pojo;
/**
* 部门实体
*/
public class Department {
private Integer deptId;
private String deptName;
public Department() {
}
public Department(Integer deptId, String deptName) {
this.deptId = deptId;
this.deptName = deptName;
}
public Integer getDeptId() {
return deptId;
}
public void setDeptId(Integer deptId) {
this.deptId = deptId;
}
public String getDeptName() {
return deptName;
}
public void setDeptName(String deptName) {
this.deptName = deptName;
}
}
package com.xuxu.dao.impl;
import com.xuxu.pojo.Department;
import com.xuxu.pojo.User;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* 用户数据访问层实现类
*/
@Component
public class UserDaoImpl {
public static List userList;
/**
* 模拟数据
*/
static {
userList = new ArrayList();
userList.add(new User(1001, "用户1", "[email protected]", 1, new Date(), new Department(101, "部门1")));
userList.add(new User(1002, "用户2", "[email protected]", 1, new Date(), new Department(102, "部门2")));
userList.add(new User(1003, "用户3", "[email protected]", 0, new Date(), new Department(103, "部门3")));
userList.add(new User(1004, "用户4", "[email protected]", 0, new Date(), new Department(104, "部门4")));
userList.add(new User(1005, "用户5", "[email protected]", 1, new Date(), new Department(105, "部门5")));
userList.add(new User(1006, "用户6", "[email protected]", 0, new Date(), new Department(101, "部门6")));
userList.add(new User(1007, "用户7", "[email protected]", 1, new Date(), new Department(102, "部门7")));
userList.add(new User(1008, "用户8", "[email protected]", 0, new Date(), new Department(103, "部门8")));
userList.add(new User(1009, "用户9", "[email protected]", 1, new Date(), new Department(104, "部门9")));
}
public List getUserList() {
return userList;
}
}
package com.xuxu.controller;
import com.xuxu.dao.impl.UserDaoImpl;
import com.xuxu.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpSession;
import java.util.List;
/**
* @author Administrator
* @create 2019/2/27
* 用户控制层
*/
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private UserDaoImpl userDaoImpl;
/**
* @param username 前端传入用户名
* @param password 前端传入密码
* @param httpSession session存放登录用户信息
* @return 重定向页面
*/
@PostMapping("/login")
public String login(String username, String password,HttpSession httpSession) {
/**
* 当账号不为空,密码为 123456 时,模拟登录成功,否则失败时重定向返回登录页面
* 重定向时 要以 "/" 开头表示应用根地址
*/
if (!StringUtils.isEmpty(username) && "123456".equals(password)) {
httpSession.setAttribute("userName",username);
return "redirect:/userList";
}else{
//重定向到index页面,index是之后要配置的请求路径之一
return "redirect:/index";
}
}
/**
*查询用户列表
* @param model
* @return 用户列表
*/
@GetMapping("users")
public String getAllUser(Model model){
List userList = userDaoImpl.getUserList();
model.addAttribute("userList",userList);
/** 往前端 Thymeleaf 模板引擎时,开头不要加 "/" ,因为它默认配置的前缀就是:
* spring.thymeleaf.prefix=classpath:/templates/
*/
return "userList";
}
}
Dashboard Template for Bootstrap
Section title
用户ID
用户名
邮箱
性别
生日
部门ID
部门名
操作
[[${user.uName}]]
编辑