需求分析:用户使用该登录模块进行登录时,当密码误输入了空格时,自动去除空格进行登录验证
使用工具:Maven、Tomcat、Druid
架构分析:
1、使用Mybatis完成jdbc和druid的dao数据层的连接
2、使用Servlet完成web表现层的数据请求和数据响应
3、使用Spring完成service层的逻辑整合
4、关键点:使用aop进行切入,对用户输入的密码进行去除空格后返回
依赖需求:
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!--apache的IO辅助工具-->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
<scope>provided</scope>
</dependency>
<!--mybatis的依赖-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.5</version>
</dependency>
<!--mysql驱动的依赖-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.29</version>
</dependency>
<!--junit测试依赖-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope> test </scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.10.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.3</version>
</dependency>
<!--解决Failed to start component [StandardEngine[Tomcat]-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.2.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>5.2.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.4</version>
</dependency>
</dependencies>
2、Mybatis框架搭建:
3、使用Spring完成业务层的整合
4、使用AOP切入完成用户输入的修改
5、使用Servlet完成数据的接受和响应
6、测试:
当输入密码带有空格时,仍旧可以正常登录
7、测试过程中遇到的问题:
无论用户输入密码为什么都显示登录失败,从dao层到service层再到webServlet层都查验过后得知:
Servlet接受用户输入信息的值而业务逻辑层是以list集合接收的当:
这样去判断时,这个判断时永远成立的,因为这个user类型为List集合,默认带有“[]”,所以永远不为空,正确的判断方式应该为:
8、总结:
该模块的功能实现主要依靠于Spring 的AOP切入功能,能在不改变代码的前提下,将用户输入的信息进行修改后返回业务层进行判断
需改进的点:需要在注册模块时加上密码不可使用空格的条件,不然会导致本身有空格的密码失效!