系统架构
:整合应用系统程序大的结构。- 全局观,系统的健壮性,扛得住多少的并发量
- 系统的
复杂度
-耦合度,维护困难- 架构->降低系统的耦合度
- 现实生活中的场景->计算机
业务
才是核心,技术是辅助业务的
多张表之间存在依赖关系->耦合度,强关联性
打开
过度设计
package com.funtl.login.demo.entity;
public class User {
private String userName;
private String loginId;
private String loginPwd;
//alt + insert
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getLoginId() {
return loginId;
}
public void setLoginId(String loginId) {
this.loginId = loginId;
}
public String getLoginPwd() {
return loginPwd;
}
public void setLoginPwd(String loginPwd) {
this.loginPwd = loginPwd;
}
@Override
public String toString() {
return "User{" +
"userName=‘" + userName + ‘\‘‘ +
", loginId=‘" + loginId + ‘\‘‘ +
", loginPwd=‘" + loginPwd + ‘\‘‘ +
‘}‘;
}
}
package com.funtl.login.demo.dao;
import com.funtl.login.demo.entity.User;
public interface UserDAO {
public User login(String loginId, String loginPwd);
}
package com.funtl.login.demo.dao.impl;
import com.funtl.login.demo.dao.UserDAO;
import com.funtl.login.demo.entity.User;
public class UserDAOImpl implements UserDAO {
/**
* 功能描述
* @author HHQ
* @param loginId 登录ID
* @param loginPwd 登录密码
* @return java.lang.String 登录结果
*/
public User login(String loginId, String loginPwd) {
//if(loginId.equals("admin")) //不这样写,因为可能出现空指针异常
/*
//这样的写法可能导致sql注入-不安全
if("admin".equals(loginId) && "123456".equals(loginPwd)){
return "成功";
}*/
User user = null;
if("admin".equals(loginId)){
if("123456".equals(loginPwd)){
user = new User();
user.setLoginId("admin");
user.setLoginPwd("123456");
user.setUserName("HHQ");
}
}
return user;
}
}
shift+f6
public interface UserService {
public User login(String loginId, String loginPwd);
}
public class UserServiceImpl implements UserService {
//数据访问的具体实现
private UserDAO userDAO = new UserDAOImpl();
public User login(String loginId, String loginPwd){
return userDAO.login(loginId,loginPwd);
}
}
登录控制器
/**
* 登录控制器
* @ClassName LoginController
* @Description TODO
*
* @Author HHQ
* @Date 2020/3/25 15:44
* @Version 1.0
*/
public class LoginController extends HttpServlet {
private UserService userService = new UserServiceImpl();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doGet(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String loginId = req.getParameter("loginId");
String loginPwd = req.getParameter("loginPwd");
User user = userService.login(loginId, loginPwd);
//登录成功
if(user == null){
req.getRequestDispatcher("/fail.jsp").forward(req,resp);
}
//登录失败
else{
req.getRequestDispatcher("/success.jsp").forward(req,resp);
}
}
}
原文:https://www.cnblogs.com/hhhqqq/p/12582831.html