一.项目采用三层架构
二.整个项目结构
三.页面展示
1.登陆页面
2.管理员登陆后查询页面
3.添加用户界面
4.修改页面
四.代码展示
1.登陆
(一)dao层
public class AdminDao { private JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource()); //根据用户名,密码查询Admin对象 public Admin login(Admin admin){ String sql = "select * from admin where username = ? and password=?"; List<Admin> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Admin.class), admin.getUsername(), admin.getPassword()); if (list==null || list.size()==0){ return null; }else { return list.get(0); } } }
(二)service层
public class AdminService { private AdminDao adminDao = new AdminDao(); public Admin login(Admin admin){ Admin login = adminDao.login(admin); return login; } }
(三)web层
public class loginServlet extends HttpServlet { private AdminService adminService = new AdminService(); protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //1.判断验证码是否正确 //1.1 得到页面传入的验证码 String verifycode = request.getParameter("verifycode"); //1.2 得到session中正确的验证码 HttpSession session = request.getSession(); String checkcode = (String) session.getAttribute("CHECKCODE_SERVER"); session.removeAttribute("CHECKCODE_SERVER"); if (checkcode==null){ checkcode=""; } if (checkcode.equalsIgnoreCase(verifycode)){ System.out.println("验证码相等"); // 利用BeanUtils来会所封装前端传入的用户名密码 Map<String, String[]>