SSM开发商城

##环境搭建

1、开发环境搭建

jdk8、tomcat8、eclipse-mars

2、项目环境搭建

创建项目、添加jar包依赖(spring核心包、springMVC包、mybatis包、数据库驱动包、连接池包、Apache包、commons包、log4j、语法包jstl等)

2.1 maven添加依赖(搭建仓库、引入依赖地址pom.xml中配置)

2.2手动添加本地jar包

##SSM整合基础配置

SSM单独开发的时候:单独使用Spring 需要applicationContext.xml;单独使用springMVC时要配置springMVC.xml;单独使用mybatis需要配置mybatis.xml;

所以整合的时候我们还是需要这三个配置文件。

创建配置文件:applicationContext.xml、springMVC.xml、mybatis.xml,配置文件的头部,约束和命名空间。如果是第一次配置,每一个配置文件的官方文档中都有配置好的,下载就行。(下附)

附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:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="
	http://www.springframework.org/schema/context 
			http://www.springframework.org/schema/context/spring-context.xsd
			http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
			http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
			http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
			http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
	
	<!-- 配置数据源:spring容器装配bean -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<!-- 5.+找对应的驱动包,8+可以使用专门的驱动包 -->
		<property name="driverClass" value="com.mysql.jdbc.Driver" />
		<!-- 后面是附属的约束条件,由于环境问题可能需要;
		连接协议:数据库类型://主机地址:端口号/数据名字?约束条件 -->
		<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/shop" />
		<property name="user" value="root" />
		<property name="password" value="123456" />
	</bean>
	<!-- 配置sql对话 -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="configLocation" value="classpath:mybatis.xml" />
		<property name="dataSource" ref="dataSource" />
	</bean>
	<!-- 配置事务 -->
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource"/>
	</bean>
	<!-- 通知 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="save*" propagation="REQUIRED"/>
			<tx:method name="get*" propagation="SUPPORTS"/>
		</tx:attributes>
	</tx:advice>
	<!-- 指定扫描器 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.eikken.mapper"></property>
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>	
	</bean>
	<bean id="categoryService" class="com.eikken.service.CategoryService"></bean>
</beans>

附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:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="
	http://www.springframework.org/schema/context 
			http://www.springframework.org/schema/context/spring-context.xsd
			http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
			http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
			http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
			http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

	<mvc:annotation-driven conversion-service="conversionService" validator="validator"></mvc:annotation-driven>
</beans>

附mybatis.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="lazyLoadingEnabled" value="true" />
		<setting name="aggressiveLazyLoading" value="false" />
		<setting name="cacheEnabled" value="true"/>
	</settings>
</configuration>

ssm框架中

spring的作用是:通过注解产生一个对象,是一种粘合剂,起到对其他框架以及类的管理和粘合:对象的管理、事物的管理等以及一些其他的开发模式。主要思想:注解、反射、面向切面编程。

springMVC的作用是:基于Servlet的,代替Servlet进行前后端的交互,MVC模式进行控制。

mybatis:主要是数据库操作,动态sql语句,二级缓存等。

##在web.xml中进行配置,配置springMVC和applicationContext.xml。

附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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
 	<display-name>GouWu</display-name>
 	<welcome-file-list>
 		<welcome-file>index.html</welcome-file>
 	</welcome-file-list>
 	<!-- 加载spring容器 其实就是加载spring配置文件 -->
 	<context-param>
 		<param-name>contextConfigLocation</param-name>
 		<param-value>classpath:applicationContext.xml</param-value>
 	</context-param>
 	<!-- 配置spring的监听器 -->
 	<listener>
 		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 	</listener>
 	<!-- 加载springMVC -->
 	<servlet>
 		<servlet-name>DispatcherServlet</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>
 	</servlet>
 	<!-- url是网络访问路径,上下两个servlet-name必须一致 -->
 	<servlet-mapping>
 		<servlet-name>DispatcherServlet</servlet-name>
 		<url-pattern>*.action</url-pattern>
 	</servlet-mapping>
 	<!-- 配置filter过滤器,处理中文乱码问题。 -->
 	<!-- servlet和filter关系:就是两层关卡,配置一样 -->
 	<filter>
 		<filter-name>characterFilter</filter-name>
 		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
 	</filter>	
 	<filter-mapping>
 		<filter-name>characterFilter</filter-name>
 		<url-pattern>/*</url-pattern>
 	</filter-mapping>
 	
</web-app>

 

 

## 访问 

##访问界面

把jsp文件放在了webContent下面的web-INF下的jsp文件夹中,其他的静态资源文件放在webContent下。webContent文件夹下,除了给定的两个文件夹,其余都是开放的

 

### 访问界面

实现功能:一级目录和二级目录的展示。

1、controller和请求路径匹配方法的创建:当界面被加载的时候,数据也得加载上,所以我们依然使用和界面同一个访问请求(不需要重新写一个controller和对应方法)

2、pojo类:和要使用的数据库表对应起来即可,如果有级联需要添加关联属性(直接用外键也可以)。

3、创建mapper的接口

public interface CategoryMapper {
	//定义泛型
	//创建和数据库对应的
	public List<Category> selectAll();
}

4、创建自定义的结果集

<?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.eikken.mapper.CategoryMapper">
	<!-- select * from category where cid=1 or 1=1;
	 -->
	<!-- 自定义结果集 -->
	<resultMap type="com.eikken.pojo.Category" id="findAllCategory">
		<!-- id的标签使用来说明主键,column中填数据库表的字段名,property中填对应的pojo类属性 -->
		<id column="cid" property="cId"></id>
		<!-- result代表普通标签 -->
		<result column="cname" property="cName"></result>
		<collection property="list" ofType="com.eikken.pojo.CategorySecond">
			<id column="csid" property="csId" />
			<result column="csname" property="csName" />
			<result column="cid" property="cId" />
		</collection>
	</resultMap>
	<!-- 查询所有目录,返回查询结果集,结果集存在级联的问题
		级联存在一对一,一对多,多对多等关系。
		一对一:
		一对多:collection
		多对多:
	 -->
	<select id="selectAll" resultMap="findAllCategory">
		select category.*,categorysecond.* from category,categorysecond 
		where category.cid = categorysecond.cid
	</select>
</mapper>

5、在applicationContext中配置mapper的扫描器(第一次的话),以后不用配。

6、service业务逻辑层的创建与编写

public class CategoryService {

	@Autowired
	public CategoryMapper categoryMapper;
	/*
	 * 查询所有的目录
	 */
	public List<Category> selectAllCategory(){
		//调用mapper中方法,获取数据库操作结果
		List<Category> list=categoryMapper.selectAll();
		if(list!=null&&list.size()>0){
			return list;
		}else{
			return null;
		}
		
	}
}

7、在applicationContext中配置service的bean

8、回到controller中的方法里,向前端返回结果

可以用Model进行返回,也可以使用对话返回,还可以打包成json串,用response返回。

 

 

### 验证码的实现

使用验证码的目的是防止智能识别,就是确定是人工操作,不是机器人;

核心:随机的内容和一定程度的混淆

实现思路:

1、创建一个图片底片 2、生成随机内容 3、在图片上绘制内容 4、绘制混淆  5、输出图片

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
项目介绍: 此项目是实现商品的从后台填写商品信息、商品上架(立即上架 或 定时上架),到前台用户可见可商品后进行购买(购物车 或 立即购买)后的待结算、待支付状态,再到用户支付(模拟支付,暂时没有实现)后商品的状态为待发货,后台管理人员进行发货操作后填写运单号码并确认发货,再到用户收到商品后点击确认收货、评价订单,最后订单状态已完成的整个在线购物的商品交易流程。 * 商品上架-> 待结算 ->待支付 ->待发货 ->待收货 ->待评价 ->已完成 同时此项目配备了完善的开发文档( 60+ 页 ),涵盖了整个系统的需求分析、功能分析、系统设计、数据库设计、系统模块设计和系统实现等内容,可以为项目的学习者或使用者提供很好的辅助作用。 技术栈: Spring + SpringMVC + MyBatis + Redis + RabbitMQ + Quartz + Bootstrap 后端使用 SSM 作为主框架进行开发,集成 Redis 内存缓存、RabbitMQ 消息队列和 Quartz 作业调度框架。 前端使用 JSP 和 Bootstrap 来进行项目开发。 项目亮点: 1)使用 Spring + SpringMVC + MyBatis + Redis + RabbitMQ + Quartz + Bootstrap 进行项目整合开发 2)使用 Redis 实现购物车功能和商品信息的数据缓存功能,提高系统的响应速度并降低数据库的访问压力 3)使用 RabbitMQ 实现订单的异步化处理和系统的日志处理,提升系统对用户操作的响应速度并降低模块之间的耦合程度 4)使用 Spring AOP 在不侵入系统代码的基础上实现系统的日志收集、权限校验和数据埋点等功能 5)使用 Quartz 实现商品的自定义定时上架功能,为用户提供更高的操作灵活性

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值