Eclipse中创建SSM框架项目步骤

先看一下总体的目录结构 

 

1.导入SSM框架所需的jar包(免费的哦~)

https://download.csdn.net/download/qq_50730205/20689242?spm=1001.2014.3001.5503 

2.编写pojo层,mapper层,service层,controller层(省略..............)

3.编写配置文件

applicationContext.xml文件的配置

这个文件主要是对数据库连接,SqlSessionFactory,mapper接口,事务的相关配置

是mybatis和spring的组合(包括了原来在mybatis中要配置的SqlMapperConfig.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:aop="http://www.springframework.org/schema/aop"
       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.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop.xsd
	http://www.springframework.org/schema/tx
	http://www.springframework.org/schema/tx/spring-tx.xsd">
    <!--开启注解扫描-->
    <context:component-scan base-package="com.lxw"/>
   
    
    <!--加载属性文件 -->
	<context:property-placeholder location="classpath:database.properties" />
    
    <!--配置连接池-->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <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>
    
    <!--配置SqlSessionFactory工厂-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--加载数据库资源  -->
        <property name="dataSource" ref="dataSource"></property>
        <!--别名映射  -->
        <property name="typeAliasesPackage" value="com.lxw.pojo"></property>
    </bean>
    
    <!--配置mapper接口-->
    <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.lxw.mapper"></property>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>
    
    
    
    
    <!--配置spring声明式事务管理-->
    <!--配置事务管理器-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <!--配置事务通知-->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="find" read-only="true"/>
            <tx:method name="*" isolation="DEFAULT"></tx:method>
        </tx:attributes>
    </tx:advice>
    <!--配置AOP增强-->
    <aop:config>
        <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.lxw.serviceImpl.*ServiceImpl.*(..))"></aop:advisor>
    </aop:config>
</beans>

database.properties文件

数据库连接(根据需要修改数据库名和密码)

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/book
jdbc.username=root
jdbc.password=root

 springmvc.xml配置

这个配置文件主要是针对Controller层的

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
    
    <!--扫描注解包-->
    <context:component-scan base-package="com.lxw.controller"></context:component-scan>
    
    <!--开启注解驱动-->
    <mvc:annotation-driven></mvc:annotation-driven>
    
    <!--配置视图解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>
    
    <!--过滤静态资源-->
    <mvc:resources location="/css/" mapping="/css/**"></mvc:resources>
    <mvc:resources location="/images/" mapping="/images/**"></mvc:resources>
    <mvc:resources location="/js/" mapping="/js/**"></mvc:resources>
</beans>

 web.xml文件

这是一个主要的文件用来把之前两个配置文件加载到类中,并配置了监听器,前端控制器等

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
	http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  
  <display-name>Archetype Created Web Application</display-name>
  
  <!--配置spring监听器,默认加载WEB-INF目录下的applicationContext.xml文件-->
  <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>
  
  <!--配置前端控制器-->
  <servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
   
    <!--加载springmvc.xml配置文件-->
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:springmvc.xml</param-value>
    </init-param>
    
    <!--启动服务器创建servlet-->
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <!--配置过滤器解决中文乱码-->
  <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>
  </filter>
  <filter-mapping>
    <filter-name>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

</web-app>

到此SSM框架配置完成开始编写吧~

  • 7
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一、项目简介本课程演示的是一套基于SSM实现的校园二手平台,主要针对计算机相关专业的正在做毕设的学生与需要项目实战练习的Java学习者。课程包含:1. 项目源码、项目文档、数据库脚本、软件工具等所有资料2. 带你从零开始部署运行本套系统3. 该项目附带的源码资料可作为毕设使用4. 提供技术答疑二、技术实现后台框架:Spring、SpringMVC、MyBatisUI界面:JSP、jQuery 、BootStrap数据库:MySQL 三、系统功能该校园二手平台主要使用Java语言作为开发基础,并使用诸如JSP + SSM框架技术,Eclipse作为开发工具,MySQL作为数据库工具以及Tomcat作为Web服务器的技术。该系统主要分为前台和后台两大功能模块,共包含两个角色:用户、管理员。具体的系统功能如下:1.前台功能模块 前台首页、商品列表、商品分类、商品搜索、商品详情、加入关注、在线支付、用户注册、用户登陆、订单心、关注列表、发布物品、我的闲置、修改人个信息、退出登陆等功能。2.后台管理模块 后台系统登陆、用户管理、商品管理、订单管理、钱包管理、系统设置、个人信息、修改密码等功能。该系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的应用价值。 四、项目截图1)前台首页2)商品详情3)订单心4)后台系统登陆5)用户管理6)商品管理7)订单管理 更多Java毕设项目请关注【毕设系列课程】https://edu.csdn.net/lecturer/2104  

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值