如何在myeclipse中搭建ssm框架

最简单的ssm框架搭建方式

工具/原料

  • 电脑
  • myeclipse8.5

方式/步骤

  1. 1

    首先呢 打开eclipse点击左上角的File-->New-->Report Web Project

  2. 2

    然后在弹出的窗口输入项目名称  点击Finish

  3. 3

    项目布局

  4. 4

    接下来呢我们直接生当作Spring 在项目上右击 选择 Myeclipse-->Add Spring Cababilities 之后会弹出窗口(如图)  然后勾选JDBC(它会主动勾选三个)之后再勾选一个web3.0,再点击finish

  5. 5

    此刻的项目布局

  6. 6

    之后我们再设置装备摆设web.xml:

    <?xml version="1.0" encoding="UTF-8"?><web-app version="2.5"     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_2_5.xsd">  <welcome-file-list>    <welcome-file>index.jsp</welcome-file>  </welcome-file-list>  <filter>          <filter-name>encoding</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>encoding</filter-name>          <url-pattern>/*</url-pattern>  </filter-mapping><!-- springmvc的焦点节制器 -->  <servlet>      <servlet-name>springDispatcher</servlet-name>      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>      <init-param>          <param-name>contextConfigLocation</param-name>          <param-value>classpath:applicationContext.xml</param-value>      </init-param>      <load-on-startup>0</load-on-startup>  </servlet>  <servlet-mapping>      <servlet-name>springDispatcher</servlet-name>      <url-pattern>*.do</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>   </web-app>

  7. 7

    然后是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:mvc="http://www.springframework.org/schema/mvc"    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                         http://www.springframework.org/schema/context/spring-context-3.0.xsd                          http://www.springframework.org/schema/tx                          http://www.springframework.org/schema/tx/spring-tx-3.0.xsd                          http://www.springframework.org/schema/aop                         http://www.springframework.org/schema/aop/spring-aop-3.0.xsd                        http://www.springframework.org/schema/mvc                         http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">         <!-- 开启注解 -->    <context:annotation-config/>       <!-- 扫描包设置 -->    <context:component-scan base-package="com.tbdz.*"/>     <!-- 启用3.0新注解 -->    <mvc:annotation-driven />        <!-- 启动Spring MVC的注解功能,完当作请乞降注解POJO的映射 -->    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>        <!-- 设置装备摆设数据源 -->    <context:property-placeholder location="classpath:jdbc.properties"/>    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">        <property name="username" value="${jdbc.user}"></property>        <property name="password" value="${jdbc.password}"></property>        <property name="driverClassName" value="${jdbc.driverClass}"></property>        <property name="url" value="${jdbc.url}"></property>                <property name="maxActive" value="100" ></property>        <property name="maxIdle" value="30" ></property>        <property name="maxWait" value="10000" ></property>    </bean>        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">        <property name="dataSource" ref="dataSource"/>        <property name="configLocation" value="classpath:mybatis-config.xml"/>    </bean>        <bean id="txManager"  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">        <property name="dataSource" ref="dataSource"></property>    </bean>        <aop:config>        <aop:pointcut id="bussinessService" expression="execution(public * com.tbdz.service.*.*(..))"/>        <aop:advisor pointcut-ref="bussinessService" advice-ref="txAdvice"  />    </aop:config>        <tx:advice id="txAdvice" transaction-manager="txManager">        <tx:attributes>            <tx:method name="add*" propagation="REQUIRED"/>            <tx:method name="update*" propagation="REQUIRED" />             <tx:method name="insert*"  propagation="REQUIRED" />            <tx:method name="del*" propagation="REQUIRED" />            <tx:method name="edit*" propagation="REQUIRED" />            <tx:method name="*" propagation="REQUIRED" />        </tx:attributes>    </tx:advice>   <context:component-scan base-package="com.tbdz.*"/></beans>

  8. 8

    到这里就根基完事啦  然后再改下你本身的包名 ;再设置装备摆设下映射文件就ok

注重事项

  • 注重点窜包名以及数据库
  • 发表于 2018-03-14 00:00
  • 阅读 ( 992 )
  • 分类:其他类型

相关问题

0 条评论

请先 登录 后评论