码迷,mamicode.com
首页 > 其他好文 > 详细

SSM项目搭建步骤

时间:2019-11-15 14:17:43      阅读:64      评论:0      收藏:0      [点我收藏+]

标签:control   子模块   文件   dmi   www   manage   one   scanner   exp   

1:安装JAVA环境JDK 1.8 添加环境变量
2:安装IDEA
3:安装Maven 添加环境变量 修改配置文件
4:创建Maven项目
5:创建子模块
6:添加项目依赖
  ----java ee
    --javax.servlet-api
    --jsp-api
    --jstl
  ----spring
    --spring-core
    --spring-beans
    --spring-context
    --spring-expression
    --spring-aop
    --spring-aspects
    --spring-jdbc
    --spring-tx
    --spring-webmvc
  ----mybatis
    --mybatis
    --mybatis-spring
  ----pagehelper
    --pagehelper
  ----mysql
    --mysql-connector-java
    --druid
  ----commons
    --commons-fileupload
    --fastjson
7:添加项目依赖
8:web页面添加
9:修改web.xml 配置springMVC

<?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_3_1.xsd"
version="3.1">
<!--9.1 添加sevlet配置-->
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 添加springXML文件扫描-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring*.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!--9.2 springMVC解析路径-->
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!--9.3 =添加过滤器-->
<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>
<!--<error-page>-->
<!--<location>12</location>-->
<!--</error-page>-->
</web-app>

  


10:添加springXML文件
--添加spring-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:mvc="http://www.springframework.org/schema/mvc"
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/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">

  


<!--10.1 =添加MVC驱动-->

<mvc:annotation-driven/>

<!--10.2 =添加MVC驱动包路径-->

<context:component-scan base-package="com.nana.blog.admin.controller"/>


<!--10.3 =添加MVC路由-->

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
<mvc:view-controller path="/showLogin" view-name="login"/>
<mvc:resources mapping="/admin/css/**" location="/WEB-INF/static/admin/css/"/>
<mvc:resources mapping="/admin/js/**" location="/WEB-INF/static/admin/js/"/>
<mvc:resources mapping="/admin/img/**" location="/WEB-INF/static/admin/img/"/>
<mvc:resources mapping="/common/**" location="/WEB-INF/static/common/"/>
<mvc:resources mapping="/admin/data/**" location="/WEB-INF/data/"/>
</beans>

11:添加POJO
12:添加DAO
13:配置spring-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 http://www.springframework.org/schema/context/spring-context.xsd">

  


<!--13.1 =添加数据库链接属性-->

<context:property-placeholder location="classpath:dataSource.properties"/>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="${jdbc.driveClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.userName}"/>
<property name="password" value="${jdbc.password}"/>
<property name="initialSize" value="${jdbc.initialSize}"/>
</bean>

  


<!--13.2 =添加数据库工厂-->

<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations" value="classpath:com/nana/blog/mapper/*.xml"/>
<property name="typeAliasesPackage" value="com.nana.blog.pojo"/>
</bean>

  


<!--13.1 =扫包路径-->

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sessionFactory"/>
<property name="basePackage" value="com.nana.blog.dao"/>
</bean>
</beans>

  


14:配置spring-server.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"
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">
<context:component-scan base-package="com.nana.blog.service.impl"/>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>

</beans>

  

15:添加数据库映射文件mapper,查看mybatis复制xml格式
17:添加service接口类
18:添加impl实现service接口,
--声明@Service,
--声明@Transactional(propagation,rollbackFor)
--注入Dao
19:web模块添加Controller
--声明@Controller
--声明@@RequestMapping页面路径映射
--注入@Autowired对象服务
20:处理数据前端绑定 model.addAttribute

SSM项目搭建步骤

标签:control   子模块   文件   dmi   www   manage   one   scanner   exp   

原文地址:https://www.cnblogs.com/catyxiao/p/11865877.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!