ssm实现用户管理系统

    技术2022-07-11  101

    ssm实现用户管理系统(1)

    package com.zhongruan.bean; public class User { public User() { } public User(int id, String username, String password) { this.id = id; this.username = username; this.password = password; } public User(String username, String password) { this.username = username; this.password = password; } private int id; private String username; private String password; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public String toString() { return "User{" + "id=" + id + ", username='" + username + '\'' + ", password='" + password + '\'' + '}'; } } package com.zhongruan.controller; import com.zhongruan.bean.User; import com.zhongruan.serivce.IUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import java.util.List; @Controller @RequestMapping("/user") public class UserController { @Autowired private IUserService userService; @RequestMapping("/login.do") public ModelAndView login(User user) { boolean flag = userService.login(user.getUsername(), user.getPassword()); ModelAndView modelAndView = new ModelAndView(); if (flag) { modelAndView.setViewName("main"); } else { modelAndView.setViewName("../failure"); } return modelAndView; } @RequestMapping("/findAll.do") public ModelAndView findAll(){ List<User> userList = userService.findAll(); ModelAndView modelAndView = new ModelAndView(); modelAndView.addObject("userList",userList); modelAndView.setViewName("user-list"); return modelAndView; } } package com.zhongruan.dao; import com.zhongruan.bean.User; import java.util.List; public interface UserDao { User findUserByUserName(String username); List<User> findAll(); } package com.zhongruan.serivce.impl; import com.zhongruan.bean.User; import com.zhongruan.dao.UserDao; import com.zhongruan.serivce.IUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class UserSerivce implements IUserService { @Autowired private UserDao userDao; @Override public boolean login(String username, String password) { User user = userDao.findUserByUserName(username); if (user!=null && user.getPassword().equals(password)){ return true; } return false; } @Override public List<User> findAll() { return userDao.findAll(); } } package com.zhongruan.serivce; import com.zhongruan.bean.User; import java.util.List; public interface IUserService { boolean login(String username,String password); List<User> findAll(); }

    修改use—list.jsp

    <tbody> <c:forEach items="${userList}" var="user"> <tr> <td><input name="ids" type="checkbox"></td> <td>${user.id}</td> <td>${user.username}</td> <td>${user.password}</td> <td class="text-center"> <a href="#" class="btn bg-olive btn-xs">更新</a> <a href="#" class="btn bg-olive btn-xs">删除</a> <a href="#" class="btn bg-olive btn-xs">添加角色</a> </td> </tr> </c:forEach> </tbody>
    Processed: 0.011, SQL: 9