开发说明
开发环境
工具 | 版本 |
后台框架 | Sprig5 + SpringMVC + Mybatis |
服务器 | Tomcat 8.5.73 |
数据库 | MySQL 8.0.28 |
Build Tools | Maven 3.8.5 |
前端 | jQuery + Bootstrap + JavaScript |
开发工具 | IDEA 2022.3 |
项目界面演示
项目功能
1、介绍项目实现功能,使用到的技术点,使用到的框架,演示最终效果。
2、创建数据库和表,添加idea可视化。
3、完成SSM框架的搭建。
4、添加字符编码过滤器,实现中文编码解析。
5、使用数据库连接池技术,使用mybatis框架完成底层实体类的创建和数据访问层的实现。
6、实现登录功能。
7、实现登录成功后全部商品分页显示。
8、实现Ajax的翻页功能。
9、添加监听器,实现获取全部商品类型功能。
10、实现商品增加功能。
11、实现Ajax商品删除功能。
12、实现Ajax商品批量删除功能。
13、实现商品修改的回显功能。
14、实现商品修改功能。
15、实现按商品名称条件查询并分页功能,翻页使用Ajax技术。
16、实现按商品类型查询并分页功能,翻页使用Ajax技术。
17、实现按商品价格查询并分页功能,翻页使用Ajax技术。
18、实现按商品名称、商品类型、商品价格多条件查询并分页,翻页使用Ajax技术。
19、实现退出功能。
具体的技术指标
熟悉Spring框架的使用
熟悉SpringMVC框架的使用;
熟悉MyBatis框架的使用
掌握JSP的标签库的使用
掌握EL表达式的使用
掌握AJAX异步刷新技术的使用
掌握文件上传实现
掌握异步AJAX分页实现
熟悉企业日常的接口开发流程
熟悉企业的项目进度控制规范
建立起软件开发的基本思想和积累开发中常见的设计思路
巩固SSM框架以及JavaEE的相关知识点,增强对各个知识点的进一步认识
开发过程
1、搭建SSM框架
1.1、建库建表
DROP DATABASE IF EXISTS xiaomissm; CREATE DATABASE xiaomissm DEFAULT CHARSET utf8; /*打开DB*/ USE xiaomissm; DROP TABLE IF EXISTS `orderdetail`; DROP TABLE IF EXISTS `xmorder`; DROP TABLE IF EXISTS `carshop`; DROP TABLE IF EXISTS `address`; DROP TABLE IF EXISTS `users`; DROP TABLE IF EXISTS product_info; DROP TABLE IF EXISTS product_type; DROP TABLE IF EXISTS admin; #DROP TABLE xiaomi_admin; #################################管理员表 CREATE TABLE admin( a_id INT AUTO_INCREMENT PRIMARY KEY, a_name VARCHAR(20), a_pass VARCHAR(20) ); INSERT INTO admin(a_id,a_name,a_pass) VALUES(1,'admin','admin'); ##########################商品类型表 CREATE TABLE product_type ( type_id INT AUTO_INCREMENT PRIMARY KEY, type_name VARCHAR(20) ); ####################添加数据 INSERT INTO product_type(type_name) VALUES('手机'); INSERT INTO product_type(type_name) VALUES('电脑'); INSERT INTO product_type(type_name) VALUES('电视'); #############################商品表 CREATE TABLE product_info ( p_id INT AUTO_INCREMENT PRIMARY KEY, p_name VARCHAR(20), p_content VARCHAR(200), ##############33商品规格/简介 p_price INT, ###############价格 p_image VARCHAR(200), #############图片 p_number INT, ########数量 type_id INT, p_date DATE, FOREIGN KEY(type_id) REFERENCES product_type(type_id) ); ##添加 INSERT INTO product_info(p_name,p_content,p_price,p_image,p_number,type_id,p_date) VALUES('小米Note2','双曲面 黑色 6GB内存 64GB闪存',2899,'xmNote2.jpg',500,1,'2018-01-04'); INSERT INTO product_info(p_name,p_content,p_price,p_image,p_number,type_id,p_date) VALUES('红米Note5A','5.5英寸 粉色 2GB内存 16GB闪存',699,'hmNote5A.jpg',500,1,'2018-01-05'); INSERT INTO product_info(p_name,p_content,p_price,p_image,p_number,type_id,p_date) VALUES('红米Note4X','5.5英寸 绿色 4GB内存 64GB闪存',1299,'hmNote4X.jpg',500,1,'2018-01-06'); INSERT INTO product_info(p_name,p_content,p_price,p_image,p_number,type_id,p_date) VALUES('红米4','5英寸 金色 3GB内存 32GB闪存',999,'hm4.jpg',500,1,'2018-01-07'); INSERT INTO product_info(p_name,p_content,p_price,p_image,p_number,type_id,p_date) VALUES('红米4X','5英寸 黑色 3GB内存 32GB闪存',899,'hm4X.jpg',500,1,'2018-01-08'); INSERT INTO product_info(p_name,p_content,p_price,p_image,p_number,type_id,p_date) VALUES('小米平板3','7.9英寸 金色 4GB内存 64GB闪存',1499,'xmPad3.jpg',500,2,'2018-01-09'); INSERT INTO product_info(p_name,p_content,p_price,p_image,p_number,type_id,p_date) VALUES('小米Air12','12.5英寸 银色 4GB内存 128GB闪存',3599,'xmAir12.jpg',500,2,'2018-01-18'); INSERT INTO product_info(p_name,p_content,p_price,p_image,p_number,type_id,p_date) VALUES('小米Air13','13.3英寸 银色 8GB内存 256GB闪存',4999,'xmAir13.jpg',500,2,'2018-01-17'); INSERT INTO product_info(p_name,p_content,p_price,p_image,p_number,type_id,p_date) VALUES('小米Pro','15.6英寸 灰色 16GB内存 256GB闪存',6999,'xmPro.jpg',500,2,'2018-01-16'); INSERT INTO product_info(p_name,p_content,p_price,p_image,p_number,type_id,p_date) VALUES('小米电视4','49英寸 原装LG屏 3840×2160 真4K',3299,'xmTV4-49.jpg',500,3,'2018-01-15'); INSERT INTO product_info(p_name,p_content,p_price,p_image,p_number,type_id,p_date) VALUES('小米电视4','55英寸 原装三星屏 3840×2160 真4K',3999,'xmTV4-55.jpg',500,3,'2018-01-13'); INSERT INTO product_info(p_name,p_content,p_price,p_image,p_number,type_id,p_date) VALUES('小米电视4','65英寸 原装三星屏 3840×2160 真4K',8999,'xmTV4-65.jpg',500,3,'2018-01-22'); INSERT INTO product_info(p_name,p_content,p_price,p_image,p_number,type_id,p_date) VALUES('小米电视4A','43英寸 FHD全高清屏 1920*1080',1999,'xmTV4A-43.jpg',500,3,'2018-01-11'); INSERT INTO product_info(p_name,p_content,p_price,p_image,p_number,type_id,p_date) VALUES('小米电视4A','49英寸 FHD全高清屏 1920*1080',2299,'xmTV4A-49.jpg',500,3,'2018-01-21'); INSERT INTO product_info(p_name,p_content,p_price,p_image,p_number,type_id,p_date) VALUES('小米MIX2','全陶瓷 黑色 8GB内存 128GB闪存',4699,'xmMIX2.jpg',500,1,'2018-04-01'); INSERT INTO product_info(p_name,p_content,p_price,p_image,p_number,type_id,p_date) VALUES('小米Note3','全网通 蓝色 6GB内存 64GB闪存',2499,'xmNote3.jpg',500,1,'2018-03-01'); INSERT INTO product_info(p_name,p_content,p_price,p_image,p_number,type_id,p_date) VALUES('小米6','玻璃金属 白色 6GB内存 128GB闪存',2899,'xm6.jpg',500,1,'2018-02-01'); INSERT INTO product_info(p_name,p_content,p_price,p_image,p_number,type_id,p_date) VALUES('小米MAX2','全金属 金色 4GB内存 64GB闪存',1599,'xmMAX2.jpg',500,1,'2018-01-02'); INSERT INTO product_info(p_name,p_content,p_price,p_image,p_number,type_id,p_date) VALUES('小米5X','全金属 金色 4GB内存 64GB闪存',1499,'xm5X.jpg',500,1,'2018-01-03');
1.2、新建Maven工程
1.3、配置pom.xml
<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.jerry</groupId> <artifactId>missm</artifactId> <version>1.0</version> <packaging>war</packaging> <!-- 集中定义依赖版本号 --> <properties> <junit.version>4.12</junit.version> <spring.version>5.2.5.RELEASE</spring.version> <mybatis.version>3.5.1</mybatis.version> <mybatis.spring.version>1.3.1</mybatis.spring.version> <mybatis.paginator.version>1.2.15</mybatis.paginator.version> <mysql.version>8.0.27</mysql.version> <slf4j.version>1.6.4</slf4j.version> <druid.version>1.1.12</druid.version> <pagehelper.version>5.1.2</pagehelper.version> <jstl.version>1.2</jstl.version> <servlet-api.version>3.0.1</servlet-api.version> <jsp-api.version>2.0</jsp-api.version> <jackson.version>2.9.6</jackson.version> </properties> <dependencies> <!-- spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jms</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> </dependency> <!-- Mybatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>${mybatis.spring.version}</version> </dependency> <dependency> <groupId>com.github.miemiedev</groupId> <artifactId>mybatis-paginator</artifactId> <version>${mybatis.paginator.version}</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>${pagehelper.version}</version> </dependency> <!-- MySql --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.version}</version> </dependency> <!-- 连接池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>${druid.version}</version> </dependency> <!-- junit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <!-- JSP相关 --> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>${jstl.version}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <scope>provided</scope> <version>${jsp-api.version}</version> </dependency> <!-- Jackson Json处理工具包 --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>${jackson.version}</version> </dependency> <!-- 文件异步上传--> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.4</version> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3.1</version> </dependency> <!--log4j 日志文件--> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> </dependencies> <!-- 插件配置 --> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> <!--识别所有的配置文件--> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources> </build> </project>
1.4、目录结构
1.5、jdbc.properties
jdbc.driver=com.mysql.cj.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/xiaomissm?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true jdbc.username=root jdbc.password=root
1.6、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="mapUnderscoreToCamelCase" value="true"/> </settings> <plugins> <!--配置分页插件--> <plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin> </plugins> </configuration>
1.7 两个Spring的配置文件
applicationContext_dao.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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"> <!-- 读取jdbc.properties属性文件--> <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder> <!-- 创建数据源--> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"> <property name="driverClassName" value="${jdbc.driver}"></property> <property name="url" value="${jdbc.url}"></property> <property name="username" value="${jdbc.username}"></property> <property name="password" value="${jdbc.password}"></property> </bean> <!-- 创建SqlSessionFactoryBean--> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 配置数据源--> <property name="dataSource" ref="dataSource"></property> <!-- 配置mybatis核心配置文件--> <property name="configLocation" value="classpath:SqlMapConfig.xml"></property> <!-- 配置实体类--> <property name="typeAliasesPackage" value="com.jerry.pojo"></property> </bean> <!-- 创建mapper文件的扫描器--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.jerry.mapper"></property> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean> </beans>
applicationContext_service.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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://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 https://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- 设置业务逻辑层的包扫描器,目的是在指定的路径下,使用@Service注解的类,Spring负责创建对象,并添加依赖--> <context:component-scan base-package="com.jerry.service"></context:component-scan> <!-- 设置事务管理器--> <bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <!-- 添加事务的切面--> <tx:advice id="transactionInterceptor" transaction-manager="dataSourceTransactionManager"> <tx:attributes> <tx:method name="*select*" read-only="true"/> <tx:method name="*find*" read-only="true"/> <tx:method name="*get*" read-only="true"/> <tx:method name="*search*" read-only="true"/> <!--增删改必须支持事务--> <tx:method name="*insert*" propagation="REQUIRED"/> <tx:method name="*save*" propagation="REQUIRED"/> <tx:method name="*add*" propagation="REQUIRED"/> <tx:method name="*delete*" propagation="REQUIRED"/> <tx:method name="*remove*" propagation="REQUIRED"/> <tx:method name="*clear*" propagation="REQUIRED"/> <tx:method name="*update*" propagation="REQUIRED"/> <tx:method name="*modify*" propagation="REQUIRED"/> <tx:method name="*change*" propagation="REQUIRED"/> <tx:method name="*set*" propagation="REQUIRED"/> <!--不包含的也支持事务--> <tx:method name="*" propagation="SUPPORTS"/> </tx:attributes> </tx:advice> <!-- 完成切面和切入点的织入--> <aop:config> <aop:pointcut id="interceptor" expression="execution(* com.jerry..service.*.*(..))"/> <!--绑定--> <aop:advisor advice-ref="transactionInterceptor" pointcut-ref="interceptor"/> </aop:config> </beans>
1.8、SpringMVC.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: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 https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!--扫描控制层组件--> <context:component-scan base-package="com.jerry.controller"></context:component-scan> <!--配置视图解析器--> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/admin/"></property> <property name="suffix" value=".jsp"></property> </bean> <!-- 开启MVC的注解驱动 --> <mvc:annotation-driven/> <!-- 配置文件上传解析器--> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"></bean> </beans>
1.9、web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> <!-- 字符编码过滤器必须写在第一个,其他的框架配置写在下面--> <!-- 配置Spring的字符编码过滤器 --> <filter> <filter-name>CharacterEncodingFilter</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> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 注册SpringMVC框架--> <servlet> <servlet-name>SpringMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:SpringMVC.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>SpringMVC</servlet-name> <url-pattern>*.action</url-pattern> </servlet-mapping> <!-- 注册Spring框架--> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext_*.xml</param-value> </context-param> <!-- 欢迎页面 直接访问登陆页面--> <welcome-file-list> <welcome-file>/admin/login.jsp</welcome-file> </welcome-file-list> </web-app>
1.10、log4j.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender"> <param name="Encoding" value="UTF-8"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%-5p %d{MM-dd HH:mm:ss,SSS}%m (%F:%L) \n"/> </layout> </appender> <logger name="java.sql"> <level value="debug"/> </logger> <logger name="org.apache.ibatis"> <level value="info"/> </logger> <root> <level value="debug"/> <appender-ref ref="STDOUT"/> </root> </log4j:configuration>
1.11、index.jsp
<%-- Created by IntelliJ IDEA. User: Admin Date: 2023/2/12 Time: 11:37 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> </body> </html>
1.12、mybatis逆向工程生成pojo和mapper
MyBatisGeneratorTools自动生成mapper接口和pojo实体类
2、实现登录功能
2.1、编写业务层代码
AdminService
AdminServiceImpl
package com.jerry.service.impl; import com.jerry.mapper.AdminMapper; import com.jerry.pojo.Admin; import com.jerry.pojo.AdminExample; import com.jerry.service.AdminService; import com.jerry.utils.MD5Util; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; /** * ClassName: AdminServiceImpl * Package: com.jerry.service.impl * Description: * * @Author jerry_jy * @Create 2023-02-12 18:54 * @Version 1.0 */ @Service public class AdminServiceImpl implements AdminService { //在业务逻辑层中,一定有数据访问层的对象 @Autowired AdminMapper adminMapper; @Override public Admin login(String name, String pwd) { //根据传入的用户或到数据库中查询相应用户对象 //如果有条件,则一定要创建AdminExample的对象,用来封装条件 AdminExample example = new AdminExample(); //添加用户名a_name条件 example.createCriteria().andANameEqualTo(name); List<Admin> list = adminMapper.selectByExample(example); if (list.size()>0){ Admin admin = list.get(0); //如果查询到用户,再进行密码的密文比对,注意密码是密文的 /** * admin.getApass ==> d033e22ae348aeb5660fc2140aec35850c4da997 * pwd ==> admin * 在进行密码的密文对比时,将用户从前端页面输入的密码pwd进行md5加密,再与数据库中的查到的对象密码进行比对 */ // String md5 = MD5Util.getMD5(pwd); // if (md5==admin.getaPass()){ // return admin; // } return admin; }else { // 没查到,就返回null return null; } } }
2.2、编写控制层代码
AdminAction
package com.jerry.controller; import com.jerry.pojo.Admin; import com.jerry.service.AdminService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.http.HttpServletRequest; /** * ClassName: AdminAction * Package: com.jerry.controller * Description: * * @Author jerry_jy * @Create 2023-02-12 19:13 * @Version 1.0 */ @Controller @RequestMapping("/admin") public class AdminAction { //切记:在所有的界面层,一定有业务逻辑层的对象 @Autowired AdminService adminService; //实现登录判断,并进行相应的跳转 @RequestMapping("/login.action") public String login(String name, String pwd, HttpServletRequest request) { Admin admin = adminService.login(name, pwd); if (admin != null) { //登录成功 // request.setAttribute("admin", admin); request.getSession().setAttribute("admin", admin); return "main"; } else { //登录失败 request.setAttribute("errmsg", "用户名或密码不正确!"); return "login"; } } }
2.3、登录页
http://localhost:8080/admin/login.jsp
网络异常,图片无法展示
|
登录成功页==>商品后台管理页