CRM客户关系管理系统之day01

在这里插入图片描述
项目原型展示
在这里插入图片描述
时序图展示:
在这里插入图片描述
在这里插入图片描述

一.软件开发的生命周期

在这里插入图片描述
在这里插入图片描述

二.CRM项目的核心业务

1)CRM项目的简介:Customer Relationship Management 客户关系管理系统
企业级应用,传统应用;给销售或者贸易型公司使用,在市场,销售,服务等各个环节中维护客户关系,
CRM项目的宗旨:增加新客户,留住老客户,把已有客户转化为忠诚客户。
2)CRM是一类项目,我们的CRM是给一个大型的进出口贸易公司来使用的,做大宗商品的进出口贸易;商品是受管家管制的。
3)CRM项目的核心业务:
系统管理功能:不是直接处理业务数据,为了保证业务管理的功能正常安全运行而设计的功能。
用户登录,安全退出,登录验证等
给超级管理员,开发和运维人员使用。
业务管理功能:处理业务数据
市场活动:市场部,设计市场活动营销活动
线索:销售部(初级销售),增加线索
客户和联系人:销售部(高级销售),有效地区分和跟踪客户和联系人.
交易:销售部(高级销售),更好地区分和统计交易的各个阶段。
售后回访:客服部,妥善安排售后回访。主动提醒。
统计图表:管理层,统计交易表中各个阶段数据量。

三.CRM物理模型设计和搭建开发环境

1,crm的表结构:
tbl_user 用户表

tbl_dic_type 数据字典类型表
tbl_dic_value 数据字典值

tbl_activity 市场活动表
tbl_activity_remark 市场活动备注表

tbl_clue 线索表
tbl_clue_remark 线索备注表

tbl_clue_activity_relation 线索和市场活动的关联关系表

tbl_customer 客户表
tbl_customer_remark 客户备注表

tbl_contacts 联系人表
tbl_contacts_remark 联系人备注表

tbl_contacts_activity_relation 联系人和市场活动的关联关系表

tbl_tran 交易表
tbl_tran_remark 交易备注表
tbl_tran_history 交易历史表

tbl_task 任务表

1)主键字段:在数据库表中,如果有一组字段能够唯一确定一条记录,则可以把它们设计成表的主键字段。
推荐使用一个字段做主键,而且推荐使用没有业务含义的字段做主键,比如:id等。

      主键字段的类型和长度由主键值的生成方式来决定:
               主键值的生成方式:
	       1)自增:借助数据库自身主键生成机制
	               数值型 长度由数据量来决定

		       运行效率低
		       开发效率高
	       2)assighed:程序员手动生成主键值,唯一非空,算法.
	               hi/low:数值型 长度由数据量决定
		       UUID:字符串 长度是32位
	       3)共享主键:由另一张表的类型和长度决定
	               tbl_person         tbl_card
		       id     name        id     name
		       1001   zs          1001    card1
		       1002   ls
	       4)联合主键:由多个字段的类型和长度决定

2)外键字段:用来确定表和表之间的关系。
1)一对多:一张表(A)中的一条记录可以对应另一张表(B)中的多条记录;
另一张表(B)中的一条记录只能对应一张表(A)中的一条记录。
A(1)---------B(n)
父表 子表
tbl_student tbl_class
id name class_id id name
1001 zs 111 111 class1
1002 ls 111 222 class2
1003 ww 222
1004 zl

		添加数据时,先添加父表记录,再添加子表记录;
		删除数据时,先删除子表记录,再删除父表记录;
		查询数据时,可能会进行关联查询:
		//查询所有姓张的学生的id,name和所在班级name
		select s.id,s.name,c.name as className
		from tbl_student s
		join tbl_class c on s.class_id=c.id//假如外键不可以为空
		where s.name like 'z%'

		内连接:查询所有符合条件的数据,并且要求结果在两张表中都有相对应的记录
		左外连接:查询左侧表中所有符合条件的数据,即使在右侧表中没有相对应的记录
		         
	        *如果外键不能为空,优先使用内连接;
		 如果外键可以为空,
		                   --假如只需要查询那些在另一张表中有相对应的记录,使用内连接
				   --假如需要查询左侧表中所有符合条件的记录,使用左外连接.
    2)一对一:一张表(A)中的一条记录只能对应另一张表(B)中的一条记录;
              另一张表(B)中的一条记录也只能对应一张表(A)中的一条记录。
		tbl_person         tbl_card
		id     name        id     name
		1001   zs          1001    card1
	       a)共享主键:(不推荐)
	         添加数据:先添加先产生的表,再后产生的表记录
		 删除数据:先删除后产生的表记录,再删除先产生的表记录
		 查询数据:无需进行连接查询
		           //查询zhangsan的驾照信息  1001
			   select *
			   from tbl_card
			   where id='1001'
                   b)唯一外键:
	         tbl_person             tbl_card
		 id     name            id     name     person_id(唯一性约束)
		 1001   zs              111    card1    1001
		 1002   ls              222    card2    1002
		 1003   ww              333    card3    1003
		 *一对一就是一种特殊的一对多。
		 *操作跟一对多完全一样。
     3)多对多:一张表(A)中的一条记录可以对应另一张表(B)中的多条记录;
               另一张表(B)中的一条记录也可以对应一张表(A)中的多条记录。
	       tbl_student                    tbl_course
	       id     name                    id     name   
	       1001   zs                      111    java   
	       1002   ls                      222    mysql  
	               tbl_student_course_relation
		        student_id     course_id
			1001            111
			1001            222
			1002            111
			1002            222
	       添加数据时,先添加父表记录(tbl_student,tbl_course),再添加子表(tbl_student_course_relation)记录;
	       删除数据时,先删除子表记录(tbl_student_course_relation),再删除父表记录(tbl_student,tbl_course)
	       查询数据时,可能会进行关联查询:
	          //查询所有姓张的学生的id,name,和所选课程的name
		  select s.id,s.name,c.name as courseName
		  from tbl_student s
                      join tbl_student_course_relation scr on s.id=scr.student_id
                      join tbl_course c on scr.course_id=c.id
		  where s.name like 'z%'

3)给关于日期和时间的字段:
都按照字符串处理:
char(10) yyyy-MM-dd
char(19) yyyy-MM-dd HH:mm:ss

2,创建crm的数据库实例:
把sql脚本导入数据库实例:

3,搭建开发环境:
1)创建项目:crm-project
设置JDK.
创建工程:crm
补全目录结构:
2)添加jar包:添加依赖

四.搭建开发环境,首页功能和用户登录

1,搭建开发环境:
1)创建项目:crm-project
设置JDK.
创建工程:crm
补全目录结构:
设置编码格式:UTF-8
2)添加jar包:添加依赖—参考课件.
3)添加配置文件:参考课件.
4)添加静态页面资源:
webapps
|->stumgr
|->crm
|->.html,.css,.js,.img test.jsp
|->WEB-INF
|->web.xml
|->classes
|->lib
*web应用根目录下的内容都是不安全的,外界可以通过url直接访问;
所以,一般为了数据的安全,都会把页面放到WEB-INF下,因为WEB-INF目录下的资源是受保护的,外界不能直接访问。

http://127.0.0.1:8080/crm/test.jsp

webapps
|->stumgr
|->crm
|->.css,.js,.img
|->WEB-INF
|->web.xml
|->classes
|->lib
|->pages test.jsp
5)把crm项目部署到tomcat上:
http://127.0.0.1:8080/crm

2,首页:
1)分析需求:
2)分析与设计:
3)编码实现:
4)测试:

3,用户登录:

开始搭建项目,既然是个web项目,肯定要支持webapp,选择下面勾选的一项,点击Next
在这里插入图片描述

然后输入自己想搭建的项目名
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
添加公共依赖(pom.xml)

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>snow-tiger-crm</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>snow-tiger-crm Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <dependencies>
    <!-- MySQL数据库连接驱动 -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.43</version>
    </dependency>
    <!-- JDBC数据源连接池 -->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>1.1.1</version>
    </dependency>
    <!-- MyBatis框架依赖 -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.4.1</version>
    </dependency>

    <!-- Spring框架依赖的JAR配置 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>4.3.9.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aop</artifactId>
      <version>4.3.9.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>4.3.9.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>4.3.9.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>4.3.9.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
      <version>4.3.9.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>4.3.9.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>4.3.9.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-oxm</artifactId>
      <version>4.3.9.RELEASE</version>
    </dependency>
    <!-- Spring AOP支持-->
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjweaver</artifactId>
      <version>1.8.9</version>
    </dependency>
    <!-- MyBatis与Spring整合依赖 -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
      <version>1.3.0</version>
    </dependency>
    <!-- servlet及jstl标签库依赖的JAR配置 -->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet.jsp.jstl</groupId>
      <artifactId>jstl-api</artifactId>
      <version>1.2</version>
    </dependency>
    <dependency>
      <groupId>org.apache.taglibs</groupId>
      <artifactId>taglibs-standard-spec</artifactId>
      <version>1.2.1</version>
    </dependency>
    <dependency>
      <groupId>org.apache.taglibs</groupId>
      <artifactId>taglibs-standard-impl</artifactId>
      <version>1.2.1</version>
    </dependency>
    <!-- 加载jackson插件依赖 -->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>2.7.3</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.7.3</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
      <version>2.7.3</version>
    </dependency>
    <!--poi依赖-->
    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi</artifactId>
      <version>3.15</version>
    </dependency>
    <!-- 文件上传 -->
    <dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      <version>1.3.1</version>
    </dependency>
    <!-- Log4j2依赖的JAR配置 -->
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <version>2.3</version>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <version>2.3</version>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-jcl</artifactId>
      <version>2.3</version>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  
 <build>
 <!--设置maven对配置文件的编译选项-->
  <resources>
    <resource>
      <directory>src/main/java</directory>
      <includes>
        <include>**/*.xml</include>
      </includes>
    </resource>
    <resource>
      <directory>src/main/resources</directory>
      <includes>
        <include>**/*.*</include>
      </includes>
    </resource>
  </resources>
  </build>
</project>

添加相关配置

(1)MyBatis 配置
mybatis-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <settings>
        <setting name="logImpl" value="STDOUT_LOGGING"/>
    </settings>
    <typeAliases>
        <package name="com.example.crm.model"/>
    </typeAliases>
    <mappers>
        <package name="com.example.crm.mapper"/>
    </mappers>
</configuration>

(2)配置数据连接和事务
applicationContext-datasource.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
    <!-- 配置数据源 -->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="username" value="root"/>
        <property name="password" value="root"/>
        <property name="url" value="jdbc:mysql://192.168.223.133:3306/crm_db?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
    </bean>
    <!-- 配置SqlSessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 必须注入属性dataSource -->
        <property name="dataSource" ref="dataSource"/>
        <!-- 如果mybatis没有特殊的配置(比如别名等),configLocation可以省去 ;否则,不能省略-->
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
    </bean>
    <!-- mapper注解扫描器配置,扫描@MapperScan注解,自动生成代码对象 -->
    <bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.example.crm.mapper"/>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    </bean>

    <!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!-- 配置事务 -->
    <aop:config>
        <aop:pointcut expression="execution(* com.example.crm..service.*.*(..))" id="allMethodPointcut"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="allMethodPointcut"/>
    </aop:config>
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="add*" propagation="REQUIRED" rollback-for="Exception"/>
            <tx:method name="save*" propagation="REQUIRED" rollback-for="Exception"/>
            <tx:method name="edit*" propagation="REQUIRED" rollback-for="Exception"/>
            <tx:method name="update*" propagation="REQUIRED" rollback-for="Exception"/>
            <tx:method name="delete*" propagation="REQUIRED" rollback-for="Exception"/>
            <tx:method name="do*" propagation="REQUIRED" rollback-for="Exception"/>
            <tx:method name="*" propagation="REQUIRED" read-only="true"/>
        </tx:attributes>
    </tx:advice>
</beans>

(3)springmvc 配置
applicationContext-mvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
    <!-- dispatcherServlet截获所有URL请求 -->
    <mvc:default-servlet-handler />
    <!-- spring mvc 扫描包下的controller -->
    <context:component-scan base-package="com.example.crm.web.controller"/>
    <!-- 配置注解驱动 -->
    <mvc:annotation-driven/>
    <!-- 配置视图解析器 -->
    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/"/>
        <property name="suffix" value=".jsp"/>
    </bean>
    <!-- 配置文件上传解析器 id:必须是multipartResolver-->
    <!--<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="#{1024*1024*80}"/>
        <property name="defaultEncoding" value="utf-8"/>
    </bean>-->
</beans>

(4)spring 总配置文件
applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 加载系统配置文件 
<context:property-placeholder location="classpath:*.properties" />-->
<!-- 扫描注解 -->
<context:component-scan base-package="com.example.crm.service" />
<!-- 导入数据相关配置 -->
<import resource="applicationContext-datasource.xml" />
</beans>

web.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         id="dataservice" version="3.0">
    <display-name>dataservice application</display-name>
    <!-- spring监听器加载applicationContext.xml配置文件 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!-- spring字符过滤器 -->
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- Spring mvc分发servlet -->
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <!-- 欢迎页,默认进入index controller -->
    <welcome-file-list>
        <welcome-file>/</welcome-file>
    </welcome-file-list>
</web-app>

在这里插入图片描述
此时配置文件完毕,项目环境基本搭建完成

五.添加页面及静态资源

commons/
css/
images/
img/
js/
*.jsp

在这里插入图片描述
在这里插入图片描述
上图是将这些静态资源放在webapp文件夹下
然后配置Tomcat小猫咪
在这里插入图片描述
在这里插入图片描述
点击确认即可

六.首页功能分析与设计

在这里插入图片描述

七.首页功能实现Controller层

在这里插入图片描述
在这里插入图片描述
因为配置了视图解析器,所以可以写成以下图片所示(启动Tomcat会自动地址跳转到http://localhost:8080/crm/,下图的/默认执行,然后跳转到index.jsp页面)
在这里插入图片描述
在这里插入图片描述
记得把复制的index.html改为index.jsp
在这里插入图片描述
并且修改index.jsp的内容,在第一行添加(<%@ page contentType="text/html;charset=UTF-8" language="java" %>
在这里插入图片描述
启动Tomcat小猫咪
在这里插入图片描述
在这里插入图片描述
发现出现状态404,但是地址栏出现变化,表示它已经找到了首页。但是未成功找到并跳转到登录页(login.html),那怎么解决呢?

当然有人会问:在浏览器上访问后,
为什么要先走index.jsp,再跳转到login.jsp?
为什么不让它直接到login.jsp;
或者把登陆页面直接写到index.jsp里?

答:这是前端的默认规范,一般项目都是先走index.jsp
在这里插入图片描述

解决办法:首先就是当成功访问首页时,通过window.location向登录页面发起请求
在这里插入图片描述
将document改为window,因为window的范围更大。(window作用整个浏览器窗口,document表示的是一个文档对象,window表示的是一个窗口对象,一个窗口下可以有多个文档对象。所以一个窗口下只有一个window.location.href,但是可能有多个document.URL、document.location.href)
在这里插入图片描述
在这里插入图片描述
然后创建对应的包和对应的类,并且在applicationContext-mvc.xml配置文件加入扫描包下的controller(<context:component-scan base-package="com.example.crm.settings.web.controller"/>)
在这里插入图片描述
在UserController类中输入以下代码
在这里插入图片描述
在这里插入图片描述
因为配置了视图解析器,所以"settings/qx/user/login";前面不用加/ 和 /WEB-INF/pages/settings/qx/user/toLogin.do可以省略/WEM-INF/pages

随后修改login.htmllogin.jsp
在这里插入图片描述
login.jsp添加以下代码
在这里插入图片描述
然后Ctrl+R
在这里插入图片描述
在这里插入图片描述
因为<base href="http://127.0.0.1:8080/crm">中地址是写死的了,客户可能会以不同的路径去访问。那么这样写显然是不合适的。
因此要这样写(

<%
	String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
%>

在这里插入图片描述
在这里插入图片描述

八.登录功能分析与设计

在这里插入图片描述
在这里插入图片描述
1,同步请求和异步请求的区别:
同步请求:浏览器窗口发出的请求,响应信息返回到浏览器窗口,所以会进行全局刷新。
异步请求:ajax发出的请求,响应信息返回到ajax的回调函数,既可以进行全局刷新,也可以进行局部刷新。

小结:如果需要进行全局刷新,推荐使用同步请求,当然也可以使用异步请求;
如果需要进行局部刷新,只能使用异步请求;
如果既可能进行全局刷新,也可能进行局部刷新,也是只能使用异步请求。

2,mybatis逆向工程:
1)简介:根据表生成mapper层三部分代码:实体类,mapper接口,映射文件。
2)使用mybatis逆向工程:
a)创建工程:crm-mybatis-generator
b)添加插件:


org.mybatis.generator
mybatis-generator-maven-plugin
1.3.2

true
true


c)添加配置文件:
数据库连接信息
代码保存的目录
表的信息
d)运行mybatis的逆向工程,根据指定表生成java代码,保存到指定的目录中。

3,使用jquery获取指定元素的指定属性的值:
选择器.attr(“属性名”);//用来获取那些值不是true/false的属性的值.
选择器.prop(“属性名”);//用来获取值是true/false的属性的值.例如:checked,selected,readonly,disabled等。

使用逆向工程
创建一个普通工程
在这里插入图片描述
添加mybatis逆向工程插件

<!--myBatis逆向工程插件-->
    <plugin>
	<groupId>org.mybatis.generator</groupId>
	<artifactId>mybatis-generator-maven-plugin</artifactId>
	<version>1.3.2</version>
	<configuration>
	    <verbose>true</verbose>
	    <overwrite>true</overwrite>
	</configuration>
    </plugin>

在这里插入图片描述
在这里插入图片描述
在resources下创建generator.properties,并修修改driverlocation的文件路径
在这里插入图片描述
创建generatorConfig.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<generatorConfiguration>

    <!--指定mysql数据库驱动-->
    <!--<classPathEntry location="E://repository-p2p//mysql//mysql-connector-java//5.1.43//mysql-connector-java-5.1.43.jar"/>-->

    <!--导入属性配置-->
    <properties resource="generator.properties"></properties>

    <!--指定特定数据库的jdbc驱动jar包的位置-->
    <classPathEntry location="${jdbc.driverLocation}"/>

    <context id="default" targetRuntime="MyBatis3">

        <!-- optional,旨在创建class时,对注释进行控制,false生成注释,true无注释 -->
        <commentGenerator>
            <property name="suppressDate" value="false"/>
            <property name="suppressAllComments" value="false"/>
        </commentGenerator>

        <!--jdbc的数据库连接 -->
        <jdbcConnection
                driverClass="${jdbc.driverClass}"
                connectionURL="${jdbc.connectionURL}"
                userId="${jdbc.userId}"
                password="${jdbc.password}">
        </jdbcConnection>


        <!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>


        <!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
            targetPackage     指定生成的model生成所在的包名
            targetProject     指定在该项目下所在的路径|指定生成到的工程名称
        -->
        <javaModelGenerator targetPackage="com.example.crm.settings.domain"
                            targetProject="C:\Users\86159\IdeaProjects\snow-tiger-crm\src\main\java">

            <!-- 是否允许子包,即targetPackage.schemaName.tableName -->
            <property name="enableSubPackages" value="false"/>
            <!-- 是否对model添加 构造函数 true添加,false不添加-->
            <property name="constructorBased" value="false"/>
            <!-- 是否对类CHAR类型的列的数据进行trim操作 -->
            <property name="trimStrings" value="true"/>
            <!-- 建立的Model对象是否 不可改变  即生成的Model对象不会有 setter方法,只有构造方法 -->
            <property name="immutable" value="false"/>
        </javaModelGenerator>

        <!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
        <sqlMapGenerator targetPackage="com.example.crm.settings.mapper"
                         targetProject="C:\Users\86159\IdeaProjects\snow-tiger-crm\src\main\java">
            <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>

        <!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
                type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
                type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
                type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口
        -->
        <javaClientGenerator targetPackage="com.example.crm.settings.mapper"
                             targetProject="C:\Users\86159\IdeaProjects\snow-tiger-crm\src\main\java" type="XMLMAPPER">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>


        <table tableName="tbl_user" domainObjectName="User"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>

        <!--
                <table tableName="tbl_clue" domainObjectName="Clue"
                       enableCountByExample="false" enableUpdateByExample="false"
                       enableDeleteByExample="false" enableSelectByExample="false"
                       selectByExampleQueryId="false">
                </table>

                <table tableName="tbl_clue_activity_relation" domainObjectName="ClueActivityRelation"
                       enableCountByExample="false" enableUpdateByExample="false"
                       enableDeleteByExample="false" enableSelectByExample="false"
                       selectByExampleQueryId="false">
                </table>

                <table tableName="tbl_clue_remark" domainObjectName="ClueRemark"
                       enableCountByExample="false" enableUpdateByExample="false"
        enableDeleteByExample="false" enableSelectByExample="false"
        selectByExampleQueryId="false">
    </table>
    -->
        <!--
        <table tableName="tbl_contacts" domainObjectName="Contacts"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>
        <table tableName="tbl_contacts_activity_relation" domainObjectName="ContactsActivityRelation"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>
        <table tableName="tbl_contacts_remark" domainObjectName="ContactsRemark"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>
        -->
        <!--
        <table tableName="tbl_customer" domainObjectName="Customer"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>

        <table tableName="tbl_customer_remark" domainObjectName="CustomerRemark"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>
        -->
        <!--
                <table tableName="tbl_dictionary_type" domainObjectName="DictionaryType"
                       enableCountByExample="false" enableUpdateByExample="false"
                       enableDeleteByExample="false" enableSelectByExample="false"
                       selectByExampleQueryId="false">
                </table>


                <table tableName="tbl_dictionary_value" domainObjectName="DictionaryValue"
                       enableCountByExample="false" enableUpdateByExample="false"
                       enableDeleteByExample="false" enableSelectByExample="false"
                       selectByExampleQueryId="false">
                </table>


                <table tableName="tbl_marketing_activities" domainObjectName="MarketingActivities"
                       enableCountByExample="false" enableUpdateByExample="false"
                       enableDeleteByExample="false" enableSelectByExample="false"
                       selectByExampleQueryId="false">
                </table>


                <table tableName="tbl_marketing_activities_remark" domainObjectName="MarketingActivitiesRemark"
                       enableCountByExample="false" enableUpdateByExample="false"
                       enableDeleteByExample="false" enableSelectByExample="false"
                       selectByExampleQueryId="false">
                </table>


        <table tableName="tbl_transaction" domainObjectName="Transaction"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>
        <table tableName="tbl_transaction_history" domainObjectName="TransactionHistory"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>
        <table tableName="tbl_transaction_remark" domainObjectName="TransactionRemark"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>
         -->
    </context>
</generatorConfiguration>

这个是要改为你项目的路径

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
注意,上图路径不能有中文路径,而且路径为/斜杠而不是\斜杠,反正我报了错(我已经进行了修改),否则会乱码报错,当前也要记得建数据库名。
在这里插入图片描述
点击上图的打勾,然后运行,发现报错( Unknown system variable 'tx_isolation'
在这里插入图片描述
后来发现我本地mysql版本和老师给的版本是不一样的,老师是5版本的。
在这里插入图片描述

经过在mysql进行查询,发现的确是这个问题
在这里插入图片描述
tx_isolation换成transaction_isolation,就可以显示结果
在这里插入图片描述
所以我决定改把Maven依赖改为8版本
在这里插入图片描述
也不要忘了这里也要改
在这里插入图片描述
在这里插入图片描述
用我自己本地的mysql-connector-java-8.0.23.jar包
果然成功了(真相只有一个)
在这里插入图片描述
在这里插入图片描述
首先在utils包下建立工具类DateUtils,方便后期日期格式化调用。
在这里插入图片描述
在domain创建ReturnObject(这里为了方便,我就在实体类加上Data注解)
在这里插入图片描述

在UserMapper接口创建方法
在这里插入图片描述

在UserMapper.xml
在这里插入图片描述
至于<include refid="Base_Column_list"/>指的是下图圈起来的代码,为了方便代码复用,进行封装
在这里插入图片描述

在service包下创建UserService
在这里插入图片描述
创建对应的实现类UserServiceImpl,记得要加Service注解
在这里插入图片描述
在UserController写业务登录逻辑
在这里插入图片描述

// 用于将返回值渲染到到浏览器上
    @RequestMapping("settings/qx/user/login.do")
    public @ResponseBody Object login(String loginAct, String loginPwd, String isRemPwd, HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        map.put("loginAct", loginAct);
        map.put("loginPwd", loginPwd);
        User user = userService.queryUserByLoginActAndPwd(map);

        ReturnObject returnObject = new ReturnObject();
        // 如果用户为空,说明数据库没有该用户的登录信息
        if (user == null) {
            returnObject.setCode("0");
            returnObject.setMessage("用户名为空或用户名密码错误");
        } else {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String nowStr = sdf.format(new Date());
            // 登录失败,表示账号已经过期
            if (nowStr.compareTo(user.getExpiretime()) > 0) {
                returnObject.setCode("0");
                returnObject.setMessage("账号已过期");
            } else if ("0".equals(user.getLockstate())) {
                // 登录失败,账号已经被锁定
                returnObject.setCode("0");
                returnObject.setMessage("账号被锁定");
            } else if (!user.getAllowips().contains(request.getRemoteAddr())) {
                // 登录失败,用户登录的id不包含请求的ip地址
                returnObject.setCode("0");
                returnObject.setMessage("ip受限");

            } else {
                // 用户登录成功
                returnObject.setCode("1");
                returnObject.setMessage("用户登录成功");
            }
        }
        return returnObject;

    }

此时代码可以优化:
先在constants包下建立一个常量类Constans.java
在这里插入图片描述
在这里插入图片描述

  // 用于将返回值渲染到到浏览器上
    @RequestMapping("settings/qx/user/login.do")
    public @ResponseBody Object login(String loginAct, String loginPwd, String isRemPwd, HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        map.put("loginAct", loginAct);
        map.put("loginPwd", loginPwd);
        User user = userService.queryUserByLoginActAndPwd(map);

        ReturnObject returnObject = new ReturnObject();
        // 如果用户为空,说明数据库没有该用户的登录信息
        if (user == null) {
            returnObject.setCode(Constants.RETURN_OBJECT_CODE_FAIL);
            returnObject.setMessage("用户名为空或用户名密码错误");
        } else {
            /*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");*/
          /*  String nowStr = sdf.format(new Date());*/
            String nowStr = DateUtils.formatDate(new Date());
            // 登录失败,表示账号已经过期
            if (nowStr.compareTo(user.getExpiretime()) > 0) {
                returnObject.setCode(Constants.RETURN_OBJECT_CODE_FAIL);
                returnObject.setMessage("账号已过期");
            } else if ("0".equals(user.getLockstate())) {
                // 登录失败,账号已经被锁定
                returnObject.setCode(Constants.RETURN_OBJECT_CODE_FAIL);
                returnObject.setMessage("账号被锁定");
            } else if (!user.getAllowips().contains(request.getRemoteAddr())) {
                // 登录失败,用户登录的id不包含请求的ip地址
                returnObject.setCode(Constants.RETURN_OBJECT_CODE_FAIL);
                returnObject.setMessage("ip受限");
            } else {
                // 用户登录成功
                returnObject.setCode(Constants.RETURN_OBJECT_CODE_SUCCESS);
                returnObject.setMessage("用户登录成功");
            }
        }
        return returnObject;
    }

webappuser包下的login.jsp进行修改
在这里插入图片描述
然后
在这里插入图片描述
发起ajax请求
在这里插入图片描述

 <script type="text/javascript">
        $(function () {
            $("#loginBtn").click(function () {
                var loginAct = $.trim($("#loginAct").val())
                var loginPwd = $.trim($("#loginPwd").val())
                var isRemPwd = $("#isRemPwd").prop("checked")
                if (loginAct === '') {
                    alert('用户名为空')
                    return
                }
                if (loginPwd === '') {
                    alert('用户密码为空')
                    return
                }
                $.ajax({
                    url: 'settings/qx/user/login.do',
                    data: {
                        loginAct: loginAct,
                        loginPwd: loginPwd,
                        isRemPwd: isRemPwd
                    },
                    type: 'post',
                    dataType: 'json',
                    success: function (data) {
                    // 响应转态码为1,成功登录并跳转到主页面。
                        if (data.code === '1') {
                            window.location.href('workbench/index.do')
                        } else {
                        // 失败则发出提示错误信息
                            $("#msg").text = data.message
                        }
                    }

                })

            })
        })
    </script>

workbench包下创建WorkbenchIndexController.java
因为还要进行跳转
在这里插入图片描述
所以在workbench包下创建WorkbenchIndexController类开控制跳转。
在这里插入图片描述
对了,忘了加这个了。
在这里插入图片描述
然后index.html也要记得改成index.jsp
在这里插入图片描述
然后启动Tomcat,发现运行报错(流下了没技术的泪水)

18:48:28.848 [RMI TCP Connection(3)-127.0.0.1] ERROR org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.crm.settings.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:171) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at javax.servlet.GenericServlet.init(GenericServlet.java:158) ~[servlet-api.jar:4.0.FR]
	at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1134) ~[catalina.jar:9.0.37]
	at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1089) ~[catalina.jar:9.0.37]
	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:983) ~[catalina.jar:9.0.37]
	at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4864) ~[catalina.jar:9.0.37]
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5173) ~[catalina.jar:9.0.37]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[catalina.jar:9.0.37]
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717) ~[catalina.jar:9.0.37]
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690) ~[catalina.jar:9.0.37]
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705) ~[catalina.jar:9.0.37]
	at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1727) ~[catalina.jar:9.0.37]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_292]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_292]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_292]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_292]
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:288) ~[tomcat-coyote.jar:9.0.37]
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) ~[?:1.8.0_292]
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) ~[?:1.8.0_292]
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:456) ~[catalina.jar:9.0.37]
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:405) ~[catalina.jar:9.0.37]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_292]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_292]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_292]
[2022-03-10 06:48:28,904] Artifact snow-tiger-crm:war: Artifact is deployed successfully
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_292]
[2022-03-10 06:48:28,904] Artifact snow-tiger-crm:war: Deploy took 17,360 milliseconds
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:288) ~[tomcat-coyote.jar:9.0.37]
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) ~[?:1.8.0_292]
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) ~[?:1.8.0_292]
	at com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468) ~[?:1.8.0_292]
	at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) ~[?:1.8.0_292]
	at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) ~[?:1.8.0_292]
	at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) ~[?:1.8.0_292]
	at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_292]
	at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1408) ~[?:1.8.0_292]
	at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) ~[?:1.8.0_292]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_292]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_292]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_292]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_292]
	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357) ~[?:1.8.0_292]
	at sun.rmi.transport.Transport$1.run(Transport.java:200) ~[?:1.8.0_292]
	at sun.rmi.transport.Transport$1.run(Transport.java:197) ~[?:1.8.0_292]
	at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_292]
	at sun.rmi.transport.Transport.serviceCall(Transport.java:196) ~[?:1.8.0_292]
	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573) ~[?:1.8.0_292]
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834) ~[?:1.8.0_292]
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688) ~[?:1.8.0_292]
	at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_292]
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687) [?:1.8.0_292]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_292]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_292]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_292]
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.crm.settings.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1493) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	... 69 more
18:48:29.930 [http-nio-8080-exec-1] ERROR org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.crm.settings.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494) [spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:171) [spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at javax.servlet.GenericServlet.init(GenericServlet.java:158) [servlet-api.jar:4.0.FR]
	at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1134) [catalina.jar:9.0.37]
	at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1089) [catalina.jar:9.0.37]
	at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:761) [catalina.jar:9.0.37]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135) [catalina.jar:9.0.37]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [catalina.jar:9.0.37]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) [catalina.jar:9.0.37]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [catalina.jar:9.0.37]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [catalina.jar:9.0.37]
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690) [catalina.jar:9.0.37]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [catalina.jar:9.0.37]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [catalina.jar:9.0.37]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373) [tomcat-coyote.jar:9.0.37]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-coyote.jar:9.0.37]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-coyote.jar:9.0.37]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1589) [tomcat-coyote.jar:9.0.37]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-coyote.jar:9.0.37]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_292]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_292]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:9.0.37]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_292]
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.crm.settings.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1493) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	... 39 more
18:48:31.338 [http-nio-8080-exec-4] ERROR org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.crm.settings.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494) [spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:171) [spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at javax.servlet.GenericServlet.init(GenericServlet.java:158) [servlet-api.jar:4.0.FR]
	at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1134) [catalina.jar:9.0.37]
	at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1089) [catalina.jar:9.0.37]
	at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:761) [catalina.jar:9.0.37]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135) [catalina.jar:9.0.37]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [catalina.jar:9.0.37]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) [catalina.jar:9.0.37]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [catalina.jar:9.0.37]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [catalina.jar:9.0.37]
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690) [catalina.jar:9.0.37]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [catalina.jar:9.0.37]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [catalina.jar:9.0.37]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373) [tomcat-coyote.jar:9.0.37]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-coyote.jar:9.0.37]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-coyote.jar:9.0.37]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1589) [tomcat-coyote.jar:9.0.37]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-coyote.jar:9.0.37]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_292]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_292]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:9.0.37]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_292]
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.crm.settings.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1493) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
	... 39 more

在这里插入图片描述
在这里插入图片描述
Http状态码是500服务器内部错误,一般来说是代码错误的问题,于是排查代码的问题,后来发现是配置文件包路径写错了。(所以说包路径尽量复制)
在这里插入图片描述

在这里插入图片描述
然后点击运行,成功启动
在这里插入图片描述
但是又出错了
在这里插入图片描述
后来发现是这个路径写错了。
在这里插入图片描述
重新运行,终于成功了。在这里插入图片描述

输入正确用户名和用户密码之后,点击登录之后,发现出现了状态500
在这里插入图片描述
在这里插入图片描述在后台代码发现发现列名不符合规范
在这里插入图片描述
改成这样
在这里插入图片描述
完整UserMapper.xml代码

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.example.crm.settings.mapper.UserMapper" >
    <resultMap id="BaseResultMap" type="com.example.crm.settings.domain.User" >
        <!--
          WARNING - @mbggenerated
          This element is automatically generated by MyBatis Generator, do not modify.
          This element was generated on Sat Oct 17 10:03:12 CST 2020.
        -->
        <id column="id" property="id" jdbcType="CHAR" />
        <result column="login_act" property="loginAct" jdbcType="VARCHAR" />
        <result column="name" property="name" jdbcType="VARCHAR" />
        <result column="login_pwd" property="loginPwd" jdbcType="VARCHAR" />
        <result column="email" property="email" jdbcType="VARCHAR" />
        <result column="expire_time" property="expireTime" jdbcType="CHAR" />
        <result column="lock_state" property="lockState" jdbcType="CHAR" />
        <result column="deptno" property="deptno" jdbcType="CHAR" />
        <result column="allow_ips" property="allowIps" jdbcType="VARCHAR" />
        <result column="createTime" property="createtime" jdbcType="CHAR" />
        <result column="create_by" property="createBy" jdbcType="VARCHAR" />
        <result column="edit_time" property="editTime" jdbcType="CHAR" />
        <result column="edit_by" property="editBy" jdbcType="VARCHAR" />
    </resultMap>
    <sql id="Base_Column_List" >
        <!--
          WARNING - @mbggenerated
          This element is automatically generated by MyBatis Generator, do not modify.
          This element was generated on Sat Oct 17 10:03:12 CST 2020.
        -->
        id, login_act, name, login_pwd, email, expire_time, lock_state, deptno, allow_ips,
        createTime, create_by, edit_time, edit_by
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
        <!--
          WARNING - @mbggenerated
          This element is automatically generated by MyBatis Generator, do not modify.
          This element was generated on Sat Oct 17 10:03:12 CST 2020.
        -->
        select
        <include refid="Base_Column_List" />
        from tbl_user
        where id = #{id,jdbcType=CHAR}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
        <!--
          WARNING - @mbggenerated
          This element is automatically generated by MyBatis Generator, do not modify.
          This element was generated on Sat Oct 17 10:03:12 CST 2020.
        -->
        delete from tbl_user
        where id = #{id,jdbcType=CHAR}
    </delete>
    <insert id="insert" parameterType="com.example.crm.settings.domain.User" >
        <!--
          WARNING - @mbggenerated
          This element is automatically generated by MyBatis Generator, do not modify.
          This element was generated on Sat Oct 17 10:03:12 CST 2020.
        -->
        insert into tbl_user (id, login_act, name,
        login_pwd, email, expire_time,
        lock_state, deptno, allow_ips,
        createTime, create_by, edit_time,
        edit_by)
        values (#{id,jdbcType=CHAR}, #{loginAct,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
        #{loginPwd,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{expireTime,jdbcType=CHAR},
        #{lockState,jdbcType=CHAR}, #{deptno,jdbcType=CHAR}, #{allowIps,jdbcType=VARCHAR},
        #{createtime,jdbcType=CHAR}, #{createBy,jdbcType=VARCHAR}, #{editTime,jdbcType=CHAR},
        #{editBy,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" parameterType="com.example.crm.settings.domain.User" >
        <!--
          WARNING - @mbggenerated
          This element is automatically generated by MyBatis Generator, do not modify.
          This element was generated on Sat Oct 17 10:03:12 CST 2020.
        -->
        insert into tbl_user
        <trim prefix="(" suffix=")" suffixOverrides="," >
            <if test="id != null" >
                id,
            </if>
            <if test="loginAct != null" >
                login_act,
            </if>
            <if test="name != null" >
                name,
            </if>
            <if test="loginPwd != null" >
                login_pwd,
            </if>
            <if test="email != null" >
                email,
            </if>
            <if test="expireTime != null" >
                expire_time,
            </if>
            <if test="lockState != null" >
                lock_state,
            </if>
            <if test="deptno != null" >
                deptno,
            </if>
            <if test="allowIps != null" >
                allow_ips,
            </if>
            <if test="createtime != null" >
                createTime,
            </if>
            <if test="createBy != null" >
                create_by,
            </if>
            <if test="editTime != null" >
                edit_time,
            </if>
            <if test="editBy != null" >
                edit_by,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides="," >
            <if test="id != null" >
                #{id,jdbcType=CHAR},
            </if>
            <if test="loginAct != null" >
                #{loginAct,jdbcType=VARCHAR},
            </if>
            <if test="name != null" >
                #{name,jdbcType=VARCHAR},
            </if>
            <if test="loginPwd != null" >
                #{loginPwd,jdbcType=VARCHAR},
            </if>
            <if test="email != null" >
                #{email,jdbcType=VARCHAR},
            </if>
            <if test="expireTime != null" >
                #{expireTime,jdbcType=CHAR},
            </if>
            <if test="lockState != null" >
                #{lockState,jdbcType=CHAR},
            </if>
            <if test="deptno != null" >
                #{deptno,jdbcType=CHAR},
            </if>
            <if test="allowIps != null" >
                #{allowIps,jdbcType=VARCHAR},
            </if>
            <if test="createtime != null" >
                #{createtime,jdbcType=CHAR},
            </if>
            <if test="createBy != null" >
                #{createBy,jdbcType=VARCHAR},
            </if>
            <if test="editTime != null" >
                #{editTime,jdbcType=CHAR},
            </if>
            <if test="editBy != null" >
                #{editBy,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.example.crm.settings.domain.User" >
        <!--
          WARNING - @mbggenerated
          This element is automatically generated by MyBatis Generator, do not modify.
          This element was generated on Sat Oct 17 10:03:12 CST 2020.
        -->
        update tbl_user
        <set >
            <if test="loginAct != null" >
                login_act = #{loginAct,jdbcType=VARCHAR},
            </if>
            <if test="name != null" >
                name = #{name,jdbcType=VARCHAR},
            </if>
            <if test="loginPwd != null" >
                login_pwd = #{loginPwd,jdbcType=VARCHAR},
            </if>
            <if test="email != null" >
                email = #{email,jdbcType=VARCHAR},
            </if>
            <if test="expireTime != null" >
                expire_time = #{expireTime,jdbcType=CHAR},
            </if>
            <if test="lockState != null" >
                lock_state = #{lockState,jdbcType=CHAR},
            </if>
            <if test="deptno != null" >
                deptno = #{deptno,jdbcType=CHAR},
            </if>
            <if test="allowIps != null" >
                allow_ips = #{allowIps,jdbcType=VARCHAR},
            </if>
            <if test="createtime != null" >
                createTime = #{createtime,jdbcType=CHAR},
            </if>
            <if test="createBy != null" >
                create_by = #{createBy,jdbcType=VARCHAR},
            </if>
            <if test="editTime != null" >
                edit_time = #{editTime,jdbcType=CHAR},
            </if>
            <if test="editBy != null" >
                edit_by = #{editBy,jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{id,jdbcType=CHAR}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.example.crm.settings.domain.User" >
        <!--
          WARNING - @mbggenerated
          This element is automatically generated by MyBatis Generator, do not modify.
          This element was generated on Sat Oct 17 10:03:12 CST 2020.
        -->
        update tbl_user
        set login_act = #{loginAct,jdbcType=VARCHAR},
        name = #{name,jdbcType=VARCHAR},
        login_pwd = #{loginPwd,jdbcType=VARCHAR},
        email = #{email,jdbcType=VARCHAR},
        expire_time = #{expireTime,jdbcType=CHAR},
        lock_state = #{lockState,jdbcType=CHAR},
        deptno = #{deptno,jdbcType=CHAR},
        allow_ips = #{allowIps,jdbcType=VARCHAR},
        createTime = #{createtime,jdbcType=CHAR},
        create_by = #{createBy,jdbcType=VARCHAR},
        edit_time = #{editTime,jdbcType=CHAR},
        edit_by = #{editBy,jdbcType=VARCHAR}
        where id = #{id,jdbcType=CHAR}
    </update>

    <select id="selectUserByLoginActAndPwd" parameterType="map" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tbl_user
        where login_act=#{loginAct} and login_pwd=#{loginPwd}
    </select>
</mapper>

经过修改,终于登陆成功
在这里插入图片描述
在使用代码生成器生成代码时,一定要注意实体类属性是否符合规范,和数据库列名是否相对应
下面是经过修改的实体类

package com.example.crm.settings.domain;

public class User {
    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.id
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    private String id;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.login_act
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    private String loginAct;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.name
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    private String name;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.login_pwd
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    private String loginPwd;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.email
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    private String email;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.expire_time
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    private String expireTime;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.lock_state
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    private String lockState;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.deptno
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    private String deptno;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.allow_ips
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    private String allowIps;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.createTime
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    private String createtime;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.create_by
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    private String createBy;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.edit_time
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    private String editTime;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.edit_by
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    private String editBy;

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.id
     *
     * @return the value of tbl_user.id
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public String getId() {
        return id;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.id
     *
     * @param id the value for tbl_user.id
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public void setId(String id) {
        this.id = id == null ? null : id.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.login_act
     *
     * @return the value of tbl_user.login_act
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public String getLoginAct() {
        return loginAct;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.login_act
     *
     * @param loginAct the value for tbl_user.login_act
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public void setLoginAct(String loginAct) {
        this.loginAct = loginAct == null ? null : loginAct.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.name
     *
     * @return the value of tbl_user.name
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public String getName() {
        return name;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.name
     *
     * @param name the value for tbl_user.name
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.login_pwd
     *
     * @return the value of tbl_user.login_pwd
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public String getLoginPwd() {
        return loginPwd;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.login_pwd
     *
     * @param loginPwd the value for tbl_user.login_pwd
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public void setLoginPwd(String loginPwd) {
        this.loginPwd = loginPwd == null ? null : loginPwd.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.email
     *
     * @return the value of tbl_user.email
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public String getEmail() {
        return email;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.email
     *
     * @param email the value for tbl_user.email
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public void setEmail(String email) {
        this.email = email == null ? null : email.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.expire_time
     *
     * @return the value of tbl_user.expire_time
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public String getExpireTime() {
        return expireTime;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.expire_time
     *
     * @param expireTime the value for tbl_user.expire_time
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public void setExpireTime(String expireTime) {
        this.expireTime = expireTime == null ? null : expireTime.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.lock_state
     *
     * @return the value of tbl_user.lock_state
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public String getLockState() {
        return lockState;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.lock_state
     *
     * @param lockState the value for tbl_user.lock_state
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public void setLockState(String lockState) {
        this.lockState = lockState == null ? null : lockState.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.deptno
     *
     * @return the value of tbl_user.deptno
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public String getDeptno() {
        return deptno;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.deptno
     *
     * @param deptno the value for tbl_user.deptno
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public void setDeptno(String deptno) {
        this.deptno = deptno == null ? null : deptno.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.allow_ips
     *
     * @return the value of tbl_user.allow_ips
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public String getAllowIps() {
        return allowIps;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.allow_ips
     *
     * @param allowIps the value for tbl_user.allow_ips
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public void setAllowIps(String allowIps) {
        this.allowIps = allowIps == null ? null : allowIps.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.createTime
     *
     * @return the value of tbl_user.createTime
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public String getCreatetime() {
        return createtime;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.createTime
     *
     * @param createtime the value for tbl_user.createTime
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public void setCreatetime(String createtime) {
        this.createtime = createtime == null ? null : createtime.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.create_by
     *
     * @return the value of tbl_user.create_by
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public String getCreateBy() {
        return createBy;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.create_by
     *
     * @param createBy the value for tbl_user.create_by
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public void setCreateBy(String createBy) {
        this.createBy = createBy == null ? null : createBy.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.edit_time
     *
     * @return the value of tbl_user.edit_time
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public String getEditTime() {
        return editTime;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.edit_time
     *
     * @param editTime the value for tbl_user.edit_time
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public void setEditTime(String editTime) {
        this.editTime = editTime == null ? null : editTime.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.edit_by
     *
     * @return the value of tbl_user.edit_by
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public String getEditBy() {
        return editBy;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.edit_by
     *
     * @param editBy the value for tbl_user.edit_by
     *
     * @mbggenerated Sat Oct 17 10:03:12 CST 2020
     */
    public void setEditBy(String editBy) {
        this.editBy = editBy == null ? null : editBy.trim();
    }
}

在这里插入图片描述
注意这里路径要修改,否则页面会有部分显示不出来

九.用户登录、安全退出

1,把控制层(controller)代码中处理好的数据传递到视图层(jsp),使用作用域传递:
pageContext:用来在同一个页面的不同标签之间传递数据。
request:在同一个请求过程中间传递数据。
session: 同一个浏览器窗口的不同请求之间传递数据。
application:所有用户共享的数据,并且长久频繁使用的数据。

<c:aaaa>
<c:bbbb>

2,jquery事件函数的用法:
选择器.click(function(){//给指定的元素添加事件
//js代码
});

选择器.click();//在指定的元素上模拟发生一次事件

3,记住密码:
访问:login.jsp---->后台:.html:如果上次记住密码,自动填上账号和密码;否则,不填。
如何判断上次是否记住密码?`
–上次登录成功,判断是否需要记住密码:如果需要记住密码,则往浏览器写cookie;否则,删除cookie。
而且cookie的值必须是该用户的loginAct和loginPwd
–下次登录时,判断该用户有没有cookie:如果有,则自动填写账号和密码;否则,不写。
而且填写的是cookie的值.
----->浏览器显示
获取cookie:
1,使用java代码获取cookie:
Cookie[] cs=request.getCookies();
for(Cookie c:cs){
if(c.getName().equals(“loginAct”)){
String loginAct=c.getValue();
}else if(c.getName().equals(“loginPwd”)){
String loginPwd=c.getValue();
}
}
2,使用EL表达式获取cookie:
${cookie.loginAct.value}
${cookie.loginPwd.value}

首先在Constans类中加入这段代码(public static final String SESSION_USER="sessionUser";)
在这里插入图片描述
然后在UserController加入以下代码
在这里插入图片描述
在这里插入图片描述

完整代码

 @RequestMapping("/settings/qx/user/login.do")
   public @ResponseBody Object login(String loginAct, String loginPwd, String isRemPwd, HttpServletRequest request, HttpSession session){
       //封装参数
       Map<String,Object> map=new HashMap<>();
       map.put("loginAct",loginAct);
       map.put("loginPwd",loginPwd);
       //调用service层方法,查询用户
       User user=userService.queryUserByLoginActAndPwd(map);

       //根据查询结果,生成响应信息
       ReturnObject returnObject=new ReturnObject();
       if(user==null){
           //登录失败,用户名或者密码错误
           returnObject.setCode(Constants.RETURN_OBJECT_CODE_FAIL);
           returnObject.setMessage("用户名或者密码错误");
       }else{//进一步判断账号是否合法
        
           if(DateUtils.formatDate(new Date()).compareTo(user.getExpireTime())>0){
               //登录失败,账号已过期
               returnObject.setCode(Constants.RETURN_OBJECT_CODE_FAIL);
               returnObject.setMessage("账号已过期");
           }else if("0".equals(user.getLockState())){
               //登录失败,状态被锁定
               returnObject.setCode(Constants.RETURN_OBJECT_CODE_FAIL);
               returnObject.setMessage("状态被锁定");
           }else if(!user.getAllowIps().contains(request.getRemoteAddr())){
               //登录失败,ip受限
               returnObject.setCode(Constants.RETURN_OBJECT_CODE_FAIL);
               returnObject.setMessage("ip受限");
           }else{
               //登录成功
               returnObject.setCode(Constants.RETURN_OBJECT_CODE_SUCCESS);
               session.setAttribute(Constants.SESSION_USER, user);

           }
       }
       return returnObject;

然后在index.jsp使用EL表达式(${sessionScope.sessionUser.name})在主页面显示成功登录的用户名
EL表达式知识学习
在这里插入图片描述

在这里插入图片描述
然后启动Tomcat小猫咪,成功登录显示用户名成功
在这里插入图片描述
login.jsp完善功能
在这里插入图片描述
当前上述代码还可以优化
在这里插入图片描述

beforeSend:function () {//当ajax向后台发送请求之前,会自动执行本函数;
                        //该函数的返回值能够决定ajax是否真正向后台发送请求:
                        //如果该函数返回true,则ajax会真正向后台发送请求;否则,如果该函数返回false,则ajax放弃向后台发送请求。
                        $("#msg").text("正在努力验证....");
                        return true;
                    }

然后登录一下
在这里插入图片描述

在这里插入图片描述
之前都是鼠标点击登录,现在我们在login.jsp加入代码支持键盘按下Enter键确认登录
在这里插入图片描述

 //给整个浏览器窗口添加键盘按下事件
            $(window).keydown(function (e) {
                //如果按的是回车键,则提交登录请求
                if(e.keyCode==13){
                    $("#loginBtn").click();
                }
            });

这里我就不截图验证啦

为了便于登录,使用Cookie(会话跟踪技术)存放用户名和密码(因为Http是一种无状态协议,在数据交换完毕之后,服务器和客户端的连接就会关闭,每次交换数据需要建立新的连接,此时服务器无法从连接上跟踪会话。而通过cookie和session的配合解决了这个问题)

Cookie 和 Session 是如何配合的呢?
用户第一次请求服务器的时候,服务器根据用户提交的相关信息,创建对应的 Session ,请求返回时将此 Session 的唯一标识信息 SessionID 返回给浏览器,浏览器接收到服务器返回的 SessionID 信息后,会将此信息存入到 Cookie 中,同时 Cookie 记录此 SessionID 属于哪个域名。

当用户第二次访问服务器的时候,请求会自动判断此域名下是否存在 Cookie 信息,如果存在自动将 Cookie 信息也发送给服务端,服务端会从 Cookie 中获取 SessionID,再根据 SessionID 查找对应的 Session 信息,如果没有找到说明用户没有登录或者登录失效,如果找到 Session 证明用户已经登录可执行后面操作。

根据以上流程可知,SessionID 是连接 Cookie 和 Session 的一道桥梁,大部分系统也是根据此原理来验证用户登录状态。

在这里插入图片描述

 //如果需要记住密码,则往外写cookie
               if("true".equals(isRemPwd)){
                   Cookie c1=new Cookie("loginAct",user.getLoginAct());
                   // 设置cookie有效存活时间
                   c1.setMaxAge(10*24*60*60);
                   response.addCookie(c1);
                   Cookie c2=new Cookie("loginPwd",user.getLoginPwd());
                   c2.setMaxAge(10*24*60*60);
                   response.addCookie(c2);
               }else{
                   //把没有过期cookie删除
                   Cookie c1=new Cookie("loginAct","1");
                   c1.setMaxAge(0);
                   response.addCookie(c1);
                   Cookie c2=new Cookie("loginPwd","1");
                   c2.setMaxAge(0);
                   response.addCookie(c2);
               }

在这里插入图片描述
那么怎么获取cookie呢?获取cookie用户名 ${cookie.loginAct.value} ${cookie.loginPwd.value}

在这里插入图片描述
在这里插入图片描述

<c:if test="${not empty cookie.loginAct and not empty cookie.loginPwd}">
								<input type="checkbox" id="isRemPwd" checked>
							</c:if>
							<c:if test="${empty cookie.loginAct or empty cookie.loginPwd}">
								<input type="checkbox" id="isRemPwd">
							</c:if>

记得也要加入标签指令支持

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

在这里插入图片描述
下一篇笔记的链接https://blog.csdn.net/ag1412/article/details/123420996

下一篇笔记

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

拭去心尘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值