中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

江蘇宏澄建設(shè)有限公司網(wǎng)站百度秒收錄技術(shù)最新

江蘇宏澄建設(shè)有限公司網(wǎng)站,百度秒收錄技術(shù)最新,東莞網(wǎng)站關(guān)鍵排名,靚號(hào)注冊(cè)網(wǎng)站免費(fèi)SSM項(xiàng)目-商城后臺(tái)管理系統(tǒng)開發(fā)說明開發(fā)環(huán)境項(xiàng)目界面演示項(xiàng)目功能具體的技術(shù)指標(biāo)開發(fā)過程1、搭建SSM框架1.1、建庫建表1.2、新建Maven工程1.3、配置pom.xml1.4、目錄結(jié)構(gòu)1.5、jdbc.properties1.6、mybatis-config.xml1.7 兩個(gè)Spring的配置文件applicationContext_dao.xmlapplica…

SSM項(xiàng)目-商城后臺(tái)管理系統(tǒng)

  • 開發(fā)說明
    • 開發(fā)環(huán)境
    • 項(xiàng)目界面演示
    • 項(xiàng)目功能
    • 具體的技術(shù)指標(biāo)
  • 開發(fā)過程
    • 1、搭建SSM框架
      • 1.1、建庫建表
      • 1.2、新建Maven工程
      • 1.3、配置pom.xml
      • 1.4、目錄結(jié)構(gòu)
      • 1.5、jdbc.properties
      • 1.6、mybatis-config.xml
      • 1.7 兩個(gè)Spring的配置文件
        • applicationContext_dao.xml
        • applicationContext_service.xml
      • 1.8、SpringMVC.xml
      • 1.9、web.xml
      • 1.10、log4j.xml
      • 1.11、index.jsp
      • 1.12、mybatis逆向工程生成pojo和mapper
    • 2、實(shí)現(xiàn)登錄功能
      • 2.1、編寫業(yè)務(wù)層代碼
      • 2.2、編寫控制層代碼
      • 2.3、登錄頁
    • 3、顯示全部商品
      • 3.1、編寫業(yè)務(wù)層代碼
      • 3.2、編寫控制層代碼
      • 3.3、商品管理頁
    • 4、分頁顯示商品
      • 4.1、編寫業(yè)務(wù)層代碼
      • 4.2、編寫控制層代碼
      • 4.3、商品分頁顯示
    • 5、新增(上架)商品
      • 5.1、獲取商品類別
      • 5.2、Ajax上傳圖片并回顯
      • 5.3、新增商品
      • 5.4、新增(上架)商品頁面展示
    • 6、更新商品
      • 6.1、回顯并更新商品
      • 6.2、頁面展示
    • 7、刪除商品
      • 7.1、單個(gè)刪除
      • 7.2、批量刪除
      • 7.3、頁面展示
    • 8、查詢商品
      • 8.0、編寫多條件查詢語句
      • 8.1、編寫業(yè)務(wù)層代碼
      • 8.2、編寫控制層代碼
      • 8.3、頁面展示
    • 9、項(xiàng)目托管
      • Gitee
      • GitHub
    • 10、項(xiàng)目所需前端頁面資料

申明: 未經(jīng)許可,禁止以任何形式轉(zhuǎn)載,若要引用,請(qǐng)標(biāo)注鏈接地址。 全文共計(jì)39077字,閱讀大概需要10分鐘
更多學(xué)習(xí)內(nèi)容, 歡迎關(guān)注我的個(gè)人公眾號(hào):不懂開發(fā)的程序猿

開發(fā)說明

開發(fā)環(huán)境

工具版本
后臺(tái)框架Sprig5 + SpringMVC + Mybatis
服務(wù)器Tomcat 8.5.73
數(shù)據(jù)庫MySQL 8.0.28
Build ToolsMaven 3.8.5
前端jQuery + Bootstrap + JavaScript
開發(fā)工具IDEA 2022.3

項(xiàng)目界面演示

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

項(xiàng)目功能

1、介紹項(xiàng)目實(shí)現(xiàn)功能,使用到的技術(shù)點(diǎn),使用到的框架,演示最終效果。

2、創(chuàng)建數(shù)據(jù)庫和表,添加idea可視化。

3、完成SSM框架的搭建。

4、添加字符編碼過濾器,實(shí)現(xiàn)中文編碼解析。

5、使用數(shù)據(jù)庫連接池技術(shù),使用mybatis框架完成底層實(shí)體類的創(chuàng)建和數(shù)據(jù)訪問層的實(shí)現(xiàn)。

6、實(shí)現(xiàn)登錄功能。

7、實(shí)現(xiàn)登錄成功后全部商品分頁顯示。

8、實(shí)現(xiàn)Ajax的翻頁功能。

9、添加監(jiān)聽器,實(shí)現(xiàn)獲取全部商品類型功能。

10、實(shí)現(xiàn)商品增加功能。

11、實(shí)現(xiàn)Ajax商品刪除功能。

12、實(shí)現(xiàn)Ajax商品批量刪除功能。

13、實(shí)現(xiàn)商品修改的回顯功能。

14、實(shí)現(xiàn)商品修改功能。

15、實(shí)現(xiàn)按商品名稱條件查詢并分頁功能,翻頁使用Ajax技術(shù)。

16、實(shí)現(xiàn)按商品類型查詢并分頁功能,翻頁使用Ajax技術(shù)。

17、實(shí)現(xiàn)按商品價(jià)格查詢并分頁功能,翻頁使用Ajax技術(shù)。

18、實(shí)現(xiàn)按商品名稱、商品類型、商品價(jià)格多條件查詢并分頁,翻頁使用Ajax技術(shù)。

19、實(shí)現(xiàn)退出功能。

具體的技術(shù)指標(biāo)

  1. 熟悉Spring框架的使用
  2. 熟悉SpringMVC框架的使用;
  3. 熟悉MyBatis框架的使用
  4. 掌握J(rèn)SP的標(biāo)簽庫的使用
  5. 掌握EL表達(dá)式的使用
  6. 掌握AJAX異步刷新技術(shù)的使用
  7. 掌握文件上傳實(shí)現(xiàn)
  8. 掌握異步AJAX分頁實(shí)現(xiàn)
  9. 熟悉企業(yè)日常的接口開發(fā)流程
  10. 熟悉企業(yè)的項(xiàng)目進(jìn)度控制規(guī)范
  11. 建立起軟件開發(fā)的基本思想和積累開發(fā)中常見的設(shè)計(jì)思路
  12. 鞏固SSM框架以及JavaEE的相關(guān)知識(shí)點(diǎn),增強(qiáng)對(duì)各個(gè)知識(shí)點(diǎn)的進(jìn)一步認(rèn)識(shí)

開發(fā)過程

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)
);####################添加數(shù)據(jù)
INSERT INTO product_type(type_name) VALUES('手機(jī)');
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商品規(guī)格/簡(jiǎn)介
p_price INT, ###############價(jià)格
p_image VARCHAR(200), #############圖片
p_number INT, ########數(shù)量
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內(nèi)存 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內(nèi)存 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內(nèi)存 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內(nèi)存 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內(nèi)存 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內(nèi)存 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內(nèi)存 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內(nèi)存 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內(nèi)存 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內(nèi)存 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','全網(wǎng)通 藍(lán)色 6GB內(nèi)存 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內(nèi)存 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內(nèi)存 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內(nèi)存 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><!-- 集中定義依賴版本號(hào) --><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相關(guān) --><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><!--識(shí)別所有的配置文件--><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、目錄結(jié)構(gòu)

在這里插入圖片描述

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 configurationPUBLIC "-//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 兩個(gè)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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttps://www.springframework.org/schema/context/spring-context.xsd"><!--    讀取jdbc.properties屬性文件--><context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder><!--    創(chuàng)建數(shù)據(jù)源--><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><!--    創(chuàng)建SqlSessionFactoryBean--><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!--        配置數(shù)據(jù)源--><property name="dataSource" ref="dataSource"></property><!--        配置mybatis核心配置文件--><property name="configLocation" value="classpath:SqlMapConfig.xml"></property><!--        配置實(shí)體類--><property name="typeAliasesPackage" value="com.jerry.pojo"></property></bean><!--    創(chuàng)建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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttps://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/aophttps://www.springframework.org/schema/aop/spring-aop.xsd"><!--    設(shè)置業(yè)務(wù)邏輯層的包掃描器,目的是在指定的路徑下,使用@Service注解的類,Spring負(fù)責(zé)創(chuàng)建對(duì)象,并添加依賴--><context:component-scan base-package="com.jerry.service"></context:component-scan><!--    設(shè)置事務(wù)管理器--><bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"/></bean><!--    添加事務(wù)的切面--><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"/><!--增刪改必須支持事務(wù)--><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"/><!--不包含的也支持事務(wù)--><tx:method name="*" propagation="SUPPORTS"/></tx:attributes></tx:advice><!--    完成切面和切入點(diǎn)的織入--><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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttps://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttps://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的注解驅(qū)動(dòng) --><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"><!--    字符編碼過濾器必須寫在第一個(gè),其他的框架配置寫在下面--><!-- 配置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><!--    注冊(cè)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><!--    注冊(cè)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: AdminDate: 2023/2/12Time: 11:37To 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自動(dòng)生成mapper接口和pojo實(shí)體類

2、實(shí)現(xiàn)登錄功能

2.1、編寫業(yè)務(wù)層代碼

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 {//在業(yè)務(wù)邏輯層中,一定有數(shù)據(jù)訪問層的對(duì)象@AutowiredAdminMapper adminMapper;@Overridepublic Admin login(String name, String pwd) {//根據(jù)傳入的用戶或到數(shù)據(jù)庫中查詢相應(yīng)用戶對(duì)象//如果有條件,則一定要?jiǎng)?chuàng)建AdminExample的對(duì)象,用來封裝條件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);//如果查詢到用戶,再進(jìn)行密碼的密文比對(duì),注意密碼是密文的/*** admin.getApass ==> d033e22ae348aeb5660fc2140aec35850c4da997* pwd ==> admin* 在進(jìn)行密碼的密文對(duì)比時(shí),將用戶從前端頁面輸入的密碼pwd進(jìn)行md5加密,再與數(shù)據(jù)庫中的查到的對(duì)象密碼進(jìn)行比對(duì)*/
//            String md5 = MD5Util.getMD5(pwd);
//            if (md5==admin.getaPass()){
//                return admin;
//            }return admin;}else {// 沒查到,就返回nullreturn 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 {//切記:在所有的界面層,一定有業(yè)務(wù)邏輯層的對(duì)象@AutowiredAdminService adminService;//實(shí)現(xiàn)登錄判斷,并進(jìn)行相應(yīng)的跳轉(zhuǎn)@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

在這里插入圖片描述

登錄成功頁==>商品后臺(tái)管理頁

在這里插入圖片描述

3、顯示全部商品

3.1、編寫業(yè)務(wù)層代碼

ProductInfoService

public interface ProductInfoService {//顯示全部商品不分頁List<ProductInfo> getAllProduct();
}

ProductInfoServiceImpl

public class ProductInfoServiceImpl implements ProductInfoService {@AutowiredProductInfoMapper productInfoMapper;@Overridepublic List<ProductInfo> getAllProduct() {return productInfoMapper.selectByExample(new ProductInfoExample());}
}

3.2、編寫控制層代碼

ProductInfoAction

@Controller
@RequestMapping("/prod")
public class ProductInfoAction {@AutowiredProductInfoService productInfoService;//顯示全部商品不分頁@RequestMapping("/getAll")private String getAllProduct(HttpServletRequest request){List<ProductInfo> list = productInfoService.getAllProduct();request.setAttribute("list", list);return "product";}}

3.3、商品管理頁

在這里插入圖片描述

4、分頁顯示商品

4.1、編寫業(yè)務(wù)層代碼

ProductInfoService

public interface ProductInfoService {//顯示全部商品不分頁List<ProductInfo> getAllProduct();//商品分頁顯示//使用mybits提供的插件,返回值是PageInfo,形參傳入(當(dāng)前頁,每頁顯示條數(shù))PageInfo splitPage(int pageNum, int pageSize);
}

ProductInfoServiceImpl

@Service
public class ProductInfoServiceImpl implements ProductInfoService {@AutowiredProductInfoMapper productInfoMapper;@Overridepublic List<ProductInfo> getAllProduct() {return productInfoMapper.selectByExample(new ProductInfoExample());}@Overridepublic PageInfo splitPage(int pageNum, int pageSize) {//分頁插件pageHelper工具類完成分頁設(shè)置//SELECT * FROM product_info LIMIT 10,5;PageHelper.startPage(pageNum, pageSize);//進(jìn)行PageInfo的數(shù)據(jù)封裝,然后返回一個(gè)pageinfo對(duì)象就行了//1、進(jìn)行條件查詢,必須創(chuàng)建ProductInfoExample對(duì)象ProductInfoExample example = new ProductInfoExample();//2、設(shè)置排序,按主鍵降序排序//SELECT * FROM product_info ORDER BY p_id DESC;example.setOrderByClause("p_id desc");//3、排完序后,取集合。切記:一定在取集合前,設(shè)置PageHelper.startPage(pageNum, pageSize);List<ProductInfo> list = productInfoMapper.selectByExample(example);//4、將倒序排的集合,封裝為PageInfoPageInfo<ProductInfo> pageInfo = new PageInfo<>(list);return pageInfo;}
}

4.2、編寫控制層代碼

@Controller
@RequestMapping("/prod")
public class ProductInfoAction {//每頁顯示的記錄數(shù)public static final int PAGE_SIZE = 5;@AutowiredProductInfoService productInfoService;//顯示全部商品不分頁@RequestMapping("/getAll")private String getAllProduct(HttpServletRequest request) {List<ProductInfo> list = productInfoService.getAllProduct();request.setAttribute("list", list);return "product";}//顯示第一頁的5條記錄@RequestMapping("/split")private String split(HttpServletRequest request) {//得到第一頁的數(shù)據(jù)PageInfo info = productInfoService.splitPage(1, PAGE_SIZE);request.setAttribute("info", info);return "product";}//Ajax分頁的翻頁處理@ResponseBody@RequestMapping("/ajaxSplit")private void ajaxSplit(int page, HttpSession session) {//取得當(dāng)前page參數(shù)的頁面數(shù)據(jù)PageInfo info = productInfoService.splitPage(page, PAGE_SIZE);session.setAttribute("info", info);}
}

4.3、商品分頁顯示

在這里插入圖片描述

5、新增(上架)商品

5.1、獲取商品類別

ProductTypeListener

package com.jerry.listener;import com.jerry.pojo.ProductType;
import com.jerry.service.ProductTypeService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.List;/*** ClassName: ProductTypeListener* Package: com.jerry.listener* Description:** @Author jerry_jy* @Create 2023-02-13 16:47* @Version 1.0*/@WebListener
public class ProductTypeListener implements ServletContextListener {@Overridepublic void contextInitialized(ServletContextEvent servletContextEvent) {//Spring注冊(cè)監(jiān)聽器也是通過ContextLoaderListener,因此我們要手動(dòng)管理ProductTypeListener//如果交給Spring管理就不知道哪個(gè)Listener先被創(chuàng)建//1、手動(dòng)從Spring容器中取出ProductTypeServiceImpl的對(duì)象ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext_*.xml");ProductTypeService productTypeService = (ProductTypeService) context.getBean("ProductTypeServiceImpl");List<ProductType> typeList = productTypeService.getAll();//2、放入全局作用域中,供新增頁面、修改頁面、前臺(tái)的查詢功能提供全部的商品類別集合servletContextEvent.getServletContext().setAttribute("typeList",typeList);}@Overridepublic void contextDestroyed(ServletContextEvent servletContextEvent) {}
}

5.2、Ajax上傳圖片并回顯

ProductInfoAction

//異步Ajax文件上傳處理
@ResponseBody
@RequestMapping("ajaxImg")
public Object ajaxImg(MultipartFile pimage,HttpServletRequest request){//1、提取、生成文件名UUID+上傳圖片后綴名.jpg .pngString saveFileName = FileNameUtil.getUUIDFileName() + FileNameUtil.getFileType(pimage.getOriginalFilename());//2、獲取圖片的存取路徑String path = request.getServletContext().getRealPath("/image_big");//3、轉(zhuǎn)存try {pimage.transferTo(new File(path+File.separator+saveFileName));} catch (IOException e) {throw new RuntimeException(e);}//返回客戶端的JSON對(duì)象, 封裝圖片路徑,為了在頁面上回顯圖片JSONObject object = new JSONObject();object.put("imgurl", saveFileName);return object.toString();
}

5.3、新增商品

業(yè)務(wù)層

ProductInfoService

//新增商品
int save(ProductInfo info);

在這里插入圖片描述

ProductInfoServiceImpl

@Override
public int save(ProductInfo info) {return productInfoMapper.insert(info);
}

控制層

ProductInfoAction

//新增商品
@RequestMapping("/save")
public String save(ProductInfo info, HttpServletRequest request) {info.setpImage(saveFileName);info.setpDate(new Date());int num=-1;try {num=productInfoService.save(info);} catch (Exception e) {throw new RuntimeException(e);}if (num>0){request.setAttribute("msg", "增加成功");}else {request.setAttribute("msg", "增加失敗");}//增加成功后應(yīng)該重新訪問數(shù)據(jù)庫,所以跳轉(zhuǎn)到分頁顯示的action上return "forward:/prod/split.action";
}

5.4、新增(上架)商品頁面展示

在這里插入圖片描述

在這里插入圖片描述

6、更新商品

6.1、回顯并更新商品

業(yè)務(wù)層

ProductInfoService

    //按主鍵id查詢商品ProductInfo selectById(int pid);//更新商品int update(ProductInfo info);

ProductInfoServiceImpl

    @Overridepublic ProductInfo selectById(int pid) {return productInfoMapper.selectByPrimaryKey(pid);}@Overridepublic int update(ProductInfo info) {return productInfoMapper.updateByPrimaryKey(info);}

控制層

ProductInfoAction

//根據(jù)主鍵id查詢商品
@RequestMapping("/one")
public String one(int pid, Model model){ProductInfo info = productInfoService.selectById(pid);model.addAttribute("prod", info);return "update";
}//更新商品@RequestMapping("/update")public String update(ProductInfo info, HttpServletRequest request) {//1、因?yàn)锳jax的異步圖片上傳,如果有上傳過,則 saveFileName 里有上傳過來的名稱,//如果沒有使用異步Ajax上傳過圖片,則saveFileName="",則實(shí)體類使用隱藏表單域提供上來的pImage原始圖片的名稱;if (!saveFileName.equals("")) {info.setpImage(saveFileName);}//完成更新處理int num = -1;//切記:對(duì)于增刪改的操作,一定要進(jìn)行try-catch的異常捕獲try {num = productInfoService.update(info);} catch (Exception e) {throw new RuntimeException(e);}if (num>0){//更新成功request.setAttribute("msg", "更新成功");}else {//更新失敗request.setAttribute("msg", "更新失敗");}//處理完更新后,saveFileName里可能有數(shù)據(jù)//而下一次使用這個(gè)變量作為判斷的依據(jù),就會(huì)出錯(cuò),所以必須清空saveFileNamesaveFileName = "";//redirect會(huì)導(dǎo)致request請(qǐng)求丟失,改用forwardreturn "forward:/prod/split.action";}

6.2、頁面展示

在這里插入圖片描述

在這里插入圖片描述

7、刪除商品

7.1、單個(gè)刪除

ProductInfoService

//單個(gè)商品的刪除
int delete(int pid);

ProductInfoServiceImpl

@Override
public int delete(int pid) {return productInfoMapper.deleteByPrimaryKey(pid);
}

ProductInfoAction

//單個(gè)刪除
@RequestMapping("/delete")
public String delete(int pid, HttpServletRequest request) {int num = -1;try {num = productInfoService.delete(pid);} catch (Exception e) {throw new RuntimeException(e);}if (num > 0) {request.setAttribute("msg", "刪除成功");} else {request.setAttribute("msg", "刪除失敗");}return "forward:/prod/deleteAjaxSplit.action";
}@ResponseBody
@RequestMapping(value = "deleteAjaxSplit", produces = "text/html;charset=UTF-8")
public Object deleteAjaxSplit(HttpServletRequest request) {//取第一頁的數(shù)據(jù)PageInfo info = productInfoService.splitPage(1, PAGE_SIZE);request.getSession().setAttribute("info", info);return request.getAttribute("msg");
}

7.2、批量刪除

ProductInfoMapper

//批量刪除商品的功能
int deleteBatch(String []ids);

ProductInfoMapper.xml

<delete id="deleteBatch">delete from product_info where p_id in<foreach collection="array" item="pid" separator="," open="(" close=")">#{pid}</foreach>
</delete>

ProductInfoService

//批量刪除商品
int deleteBatch(String []ids);

ProductInfoServiceImpl

@Override
public int deleteBatch(String[] ids) {return productInfoMapper.deleteBatch(ids);
}

ProductInfoAction

//批量刪除商品
@RequestMapping("/deleteBatch")
public String deleteBatch(String pids, HttpServletRequest request) {//將上傳上來的字符串截?cái)嚅_,形成商品id的字符數(shù)組String[] split = pids.split(",");int num = -1;try {num = productInfoService.deleteBatch(split);} catch (Exception e) {throw new RuntimeException(e);}try {if (num > 0){request.setAttribute("msg", "批量刪除成功");}else {request.setAttribute("msg", "批量刪除失敗");}} catch (Exception e) {request.setAttribute("msg", "商品不能刪除");}return "forward:/prod/deleteAjaxSplit.action";
}

7.3、頁面展示

單個(gè)刪除

在這里插入圖片描述

在這里插入圖片描述

批量刪除

在這里插入圖片描述

在這里插入圖片描述

8、查詢商品

8.0、編寫多條件查詢語句

多條件的查詢【條件】封裝在vo對(duì)象中

package com.jerry.pojo.vo;/*** ClassName: ProductInfoVo* Package: com.jerry.pojo.vo* Description:** @Author jerry_jy* @Create 2023-02-14 11:49* @Version 1.0*/
public class ProductInfoVo {//商品名稱private String pname;//商品類型private Integer typeid;//最低價(jià)格private Integer lprice;//最高價(jià)格private Integer hprice;//設(shè)置頁碼private Integer page = 1;public ProductInfoVo() {}public ProductInfoVo(String pname, Integer typeid, Integer lprice, Integer hprice, Integer page) {this.pname = pname;this.typeid = typeid;this.lprice = lprice;this.hprice = hprice;this.page = page;}public String getPname() {return pname;}public void setPname(String pname) {this.pname = pname;}public Integer getTypeid() {return typeid;}public void setTypeid(Integer typeid) {this.typeid = typeid;}public Integer getLprice() {return lprice;}public void setLprice(Integer lprice) {this.lprice = lprice;}public Integer getHprice() {return hprice;}public void setHprice(Integer hprice) {this.hprice = hprice;}public Integer getPage() {return page;}public void setPage(Integer page) {this.page = page;}@Overridepublic String toString() {return "ProductInfoVo{" +"pname='" + pname + '\'' +", typeid=" + typeid +", lprice=" + lprice +", hprice=" + hprice +", page=" + page +'}';}
}

ProductInfoMapper

//多條件查詢
List<ProductInfo> selectCondition(ProductInfoVo vo);

ProductInfoMapper.xml

 <!--
多條件查詢 拼接
List<ProductInfo> selectCondition(ProductInfoVo vo);
--><select id="selectCondition" parameterType="com.jerry.pojo.vo.ProductInfoVo" resultMap="BaseResultMap">select<include refid="Base_Column_List"></include>from product_info<!--拼接條件--><where><!--商品名稱不為空,拼接商品名稱模糊查詢--><if test="pname != null and pname != -1">and p_name like '%${pname}%'</if><!--商品類型不為空,拼接商品類型查詢--><if test="typeid != null and type != ''">and type_id = #{typeid}</if><!--如果最低價(jià)格不為空 且大于0(vo在類中實(shí)現(xiàn)),最高價(jià)格為空,則查詢大于最低價(jià)格的所有商品--><if test="(lprice != null and lprice != '') and (hprice == null or hprice == '')">and p_price &gt;= #{lprice}</if><!--如果最低價(jià)格為空,最高價(jià)格不為空 且大于0,則查詢小于最高價(jià)格的所有商品--><if test="(lprice == null or lprice == '') and (hprice != null and hprice != '')">and p_price &lt;= #{hprice}</if><!--如果最低價(jià)格不為空,最高價(jià)格不為空,則查詢介于最高價(jià)格和最低價(jià)格之間的所有商品--><if test="(lprice != null and lprice != '') and (hprice != null and hprice != '')">and p_price between #{lprice} and #{hprice}</if></where>order by p_id desc</select>

SelectConditionTest

package com.jerry;import com.jerry.mapper.ProductInfoMapper;
import com.jerry.pojo.ProductInfo;
import com.jerry.pojo.vo.ProductInfoVo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import java.util.List;/*** ClassName: SelectConditionTest* Package: com.jerry* Description:** @Author jerry_jy* @Create 2023-02-14 12:24* @Version 1.0*/@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext_dao.xml","classpath:applicationContext_service.xml"})
public class SelectConditionTest {@AutowiredProductInfoMapper productInfoMapper;@Testpublic void test(){ProductInfoVo vo = new ProductInfoVo();List<ProductInfo> list = productInfoMapper.selectCondition(vo);list.forEach(System.out::println);}
}

8.1、編寫業(yè)務(wù)層代碼

ProductInfoService

//多條件商品的查詢 分頁
PageInfo<ProductInfo> splitPageVo(ProductInfoVo vo, int pageSize);

ProductInfoServiceImpl

@Override
public PageInfo<ProductInfo> splitPageVo(ProductInfoVo vo, int pageSize) {//取出集合之前,先要取出PageHelper.startPage()屬性設(shè)置PageHelper.startPage(vo.getPage(), pageSize);List<ProductInfo> list = productInfoMapper.selectCondition(vo);return new PageInfo<>(list);
}

8.2、編寫控制層代碼

package com.jerry.controller;import com.github.pagehelper.PageInfo;
import com.jerry.pojo.ProductInfo;
import com.jerry.pojo.vo.ProductInfoVo;
import com.jerry.service.ProductInfoService;
import com.jerry.utils.FileNameUtil;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;/*** ClassName: ProductInfoAction* Package: com.jerry.controller* Description:** @Author jerry_jy* @Create 2023-02-13 11:33* @Version 1.0*/@Controller
@RequestMapping("/prod")
public class ProductInfoAction {//每頁顯示的記錄數(shù)public static final int PAGE_SIZE = 5;//異步上傳的文件圖片的名稱String saveFileName = "";@AutowiredProductInfoService productInfoService;//顯示全部商品不分頁@RequestMapping("/getAll")public String getAllProduct(HttpServletRequest request) {List<ProductInfo> list = productInfoService.getAllProduct();request.setAttribute("list", list);return "product";}//顯示第一頁的5條記錄@RequestMapping("/split")public String split(HttpServletRequest request) {PageInfo info = null;Object vo = request.getSession().getAttribute("prodVo");if (vo != null) {info = productInfoService.splitPageVo((ProductInfoVo) vo, PAGE_SIZE);request.getSession().removeAttribute("prodVo");} else {//得到第一頁的數(shù)據(jù)info = productInfoService.splitPage(1, PAGE_SIZE);}request.setAttribute("info", info);return "product";}//Ajax分頁的翻頁處理@ResponseBody@RequestMapping("/ajaxSplit")public void ajaxSplit(ProductInfoVo vo, HttpSession session) {//取得當(dāng)前page參數(shù)的頁面數(shù)據(jù)PageInfo info = productInfoService.splitPageVo(vo, PAGE_SIZE);session.setAttribute("info", info);}//異步Ajax文件上傳處理@ResponseBody@RequestMapping("ajaxImg")public Object ajaxImg(MultipartFile pimage, HttpServletRequest request) {//1、提取、生成文件名UUID+上傳圖片后綴名.jpg .pngsaveFileName = FileNameUtil.getUUIDFileName() + FileNameUtil.getFileType(pimage.getOriginalFilename());//2、獲取圖片的存取路徑String path = request.getServletContext().getRealPath("/image_big");//3、轉(zhuǎn)存try {pimage.transferTo(new File(path + File.separator + saveFileName));} catch (IOException e) {throw new RuntimeException(e);}//返回客戶端的JSON對(duì)象, 封裝圖片路徑,為了在頁面上回顯圖片JSONObject object = new JSONObject();object.put("imgurl", saveFileName);return object.toString();}//新增商品@RequestMapping("/save")public String save(ProductInfo info, HttpServletRequest request) {info.setpImage(saveFileName);info.setpDate(new Date());int num = -1;try {num = productInfoService.save(info);} catch (Exception e) {throw new RuntimeException(e);}if (num > 0) {request.setAttribute("msg", "增加成功");} else {request.setAttribute("msg", "增加失敗");}//清空saveFileName這個(gè)變量,為了下次新增或修改的異步Ajax的上傳處理saveFileName = "";//增加成功后應(yīng)該重新訪問數(shù)據(jù)庫,所以跳轉(zhuǎn)到分頁顯示的action上return "forward:/prod/split.action";}//根據(jù)主鍵id查詢商品@RequestMapping("/one")public String one(int pid, ProductInfoVo vo, Model model, HttpSession session) {ProductInfo info = productInfoService.selectById(pid);model.addAttribute("prod", info);//將多條件以及頁碼放在session中,更新處理結(jié)束后,分頁時(shí)讀取條件和頁碼session.setAttribute("prodVo", vo);return "update";}//更新商品@RequestMapping("/update")public String update(ProductInfo info, HttpServletRequest request) {//1、因?yàn)锳jax的異步圖片上傳,如果有上傳過,則 saveFileName 里有上傳過來的名稱,//如果沒有使用異步Ajax上傳過圖片,則saveFileName="",則實(shí)體類使用隱藏表單域提供上來的pImage原始圖片的名稱;if (!saveFileName.equals("")) {info.setpImage(saveFileName);}//完成更新處理int num = -1;//切記:對(duì)于增刪改的操作,一定要進(jìn)行try-catch的異常捕獲try {num = productInfoService.update(info);} catch (Exception e) {throw new RuntimeException(e);}if (num > 0) {//更新成功request.setAttribute("msg", "更新成功");} else {//更新失敗request.setAttribute("msg", "更新失敗");}//處理完更新后,saveFileName里可能有數(shù)據(jù)//而下一次使用這個(gè)變量作為判斷的依據(jù),就會(huì)出錯(cuò),所以必須清空saveFileNamesaveFileName = "";//redirect會(huì)導(dǎo)致request請(qǐng)求丟失,改用forwardreturn "forward:/prod/split.action";}//單個(gè)刪除@RequestMapping("/delete")public String delete(int pid, ProductInfoVo vo, HttpServletRequest request) {int num = -1;try {num = productInfoService.delete(pid);} catch (Exception e) {throw new RuntimeException(e);}if (num > 0) {request.setAttribute("msg", "刪除成功");request.getSession().setAttribute("deleteProductVo", vo);} else {request.setAttribute("msg", "刪除失敗");}return "forward:/prod/deleteAjaxSplit.action";}@ResponseBody@RequestMapping(value = "deleteAjaxSplit", produces = "text/html;charset=UTF-8")public Object deleteAjaxSplit(HttpServletRequest request) {//取第一頁的數(shù)據(jù)PageInfo info = null;Object vo = request.getSession().getAttribute("deleteProductVo");if (vo != null) {info = productInfoService.splitPageVo((ProductInfoVo) vo, PAGE_SIZE);} else {info = productInfoService.splitPage(1, PAGE_SIZE);}request.getSession().setAttribute("info", info);return request.getAttribute("msg");}//批量刪除商品@RequestMapping("/deleteBatch")public String deleteBatch(String pids, HttpServletRequest request) {//將上傳上來的字符串截?cái)嚅_,形成商品id的字符數(shù)組String[] split = pids.split(",");int num = -1;try {num = productInfoService.deleteBatch(split);} catch (Exception e) {throw new RuntimeException(e);}try {if (num > 0) {request.setAttribute("msg", "批量刪除成功");} else {request.setAttribute("msg", "批量刪除失敗");}} catch (Exception e) {request.setAttribute("msg", "商品不能刪除");}return "forward:/prod/deleteAjaxSplit.action";}//多條件商品的查詢@ResponseBody@RequestMapping("/condition")public void condition(ProductInfoVo vo, HttpSession session) {List<ProductInfo> list = productInfoService.selectCondition(vo);session.setAttribute("list", list);}
}

8.3、頁面展示

在這里插入圖片描述

9、項(xiàng)目托管

Gitee

https://gitee.com/jinyang-jy/xiaomissm.git

GitHub

https://github.com/Jerry-jy/missm.git

10、項(xiàng)目所需前端頁面資料

鏈接:https://pan.baidu.com/s/1CGnGV4anjBHVI_tLqLYXfw?pwd=2022
提取碼:2022

–end–

http://www.risenshineclean.com/news/21784.html

相關(guān)文章:

  • 百度關(guān)鍵詞優(yōu)化多少錢seo優(yōu)化技術(shù)教程
  • 樹在線網(wǎng)頁制作網(wǎng)站今日足球最新預(yù)測(cè)比分
  • 數(shù)據(jù)資源網(wǎng)站如何做企業(yè)策劃咨詢公司
  • 想讓一個(gè)網(wǎng)站上線需要怎么做營(yíng)銷手機(jī)系統(tǒng)安裝
  • 可以做外鏈的圖片網(wǎng)站成都網(wǎng)絡(luò)營(yíng)銷推廣公司
  • 如何做視頻網(wǎng)站流程圖關(guān)于營(yíng)銷的最新的新聞
  • 專做電器的網(wǎng)站域名注冊(cè)阿里云
  • 163企業(yè)郵箱收費(fèi)標(biāo)準(zhǔn)一年多少錢上海谷歌seo推廣公司
  • iis7.5 部署網(wǎng)站寄生蟲seo教程
  • 做素描的網(wǎng)站百度排名點(diǎn)擊軟件
  • wordpress插件更新保留修改寧波優(yōu)化推廣選哪家
  • 有沒有免費(fèi)做網(wǎng)站的百度電話客服24小時(shí)人工服務(wù)熱線
  • 得力文具網(wǎng)站建設(shè)策劃書2023搜索最多的關(guān)鍵詞
  • 武漢光谷新聞最新消息上海專業(yè)的seo推廣咨詢電話
  • 網(wǎng)站建設(shè)最貴服務(wù)商企業(yè)培訓(xùn)系統(tǒng)
  • 怎樣可以做網(wǎng)站培訓(xùn)機(jī)構(gòu)網(wǎng)站制作
  • 商城網(wǎng)站 報(bào)價(jià) 方案優(yōu)化建站
  • 公司門戶網(wǎng)站該怎么做seo建站營(yíng)銷
  • 企業(yè)網(wǎng)站功能模塊長(zhǎng)春做網(wǎng)站推廣的公司
  • 營(yíng)銷型網(wǎng)站建設(shè)教學(xué)淘寶優(yōu)秀軟文范例100字
  • 億瑪酷網(wǎng)站建設(shè)域名注冊(cè)新網(wǎng)
  • 網(wǎng)絡(luò)營(yíng)銷中自建網(wǎng)站平臺(tái)推廣方式
  • 鞍山建設(shè)局的網(wǎng)站seo快速排名系統(tǒng)
  • 專門做微信推送的網(wǎng)站廣東疫情動(dòng)態(tài)人民日?qǐng)?bào)
  • wordpress 多語言切換東莞seo排名外包
  • 做鉆石的網(wǎng)站如何推廣我的網(wǎng)站
  • quercus wordpress長(zhǎng)沙網(wǎng)站優(yōu)化價(jià)格
  • 網(wǎng)站的做公司鄭州seo建站
  • 怎么讓百度搜索靠前北京seo工程師
  • .net網(wǎng)站設(shè)計(jì)seo技術(shù)優(yōu)化