• 搭建ssm项目框架


    【声明】转载注明链接,源码联系公众号:aandb7获取

    【此处组织名groupId:com.dayuanit,可替换公司域名;项目名artifactid:...】

    此处第二个配置文件选择maven安装目录下的settings.xml(C盘的.m2/.../conf中...好像没有.xml),这个settings最好配置了阿里云,下载会比从国外的maven仓库下载jar包快;

    选择项目名,项目位置,finish;

    选择new window;

    先点auto import;

    config出来的稍晚,点config;

    OK即可;

    建立java文件夹;

     建立各种文件:

    注意我的目录文件类型与结构;

    【1】配置pom依赖↓

    在dependencies节点前面加入<properties>:

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <spring.version>5.0.3.RELEASE</spring.version>
      </properties>
    

      在dependencies节点内加入:

    <!-- Servlet -->
        <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <version>3.1.0</version>
          <scope>provided</scope>
        </dependency>
    
        <!-- jstl标签 -->
        <dependency>
          <groupId>jstl</groupId>
          <artifactId>jstl</artifactId>
          <version>1.2</version>
        </dependency>
    
        <!-- JSP -->
        <dependency>
          <groupId>javax.servlet.jsp</groupId>
          <artifactId>jsp-api</artifactId>
          <version>2.2</version>
          <scope>provided</scope>
        </dependency>
    
        <!--必备工具类commons-lang3-->
        <dependency>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-lang3</artifactId>
          <version>3.7</version>
        </dependency>
    
        <!-- springmvc所需jar -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-webmvc</artifactId>
          <version>${spring.version}</version>
        </dependency>
    
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-web</artifactId>
          <version>${spring.version}</version>
        </dependency>
    
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-aop</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-context</artifactId>
          <version>${spring.version}</version>
        </dependency>
    
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-core</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-tx</artifactId>
          <version>${spring.version}</version>
        </dependency>
    
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-expression</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-orm</artifactId>
          <version>${spring.version}</version>
        </dependency>
    
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-aspects</artifactId>
          <version>${spring.version}</version>
        </dependency>
    
    
        <!-- mybatis -->
        <dependency>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis</artifactId>
          <version>3.4.5</version>
        </dependency>
    
        <!-- mybatis-spring所需jar -->
        <dependency>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis-spring</artifactId>
          <version>1.3.0</version>
        </dependency>
        <dependency>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis</artifactId>
          <version>3.4.5</version>
        </dependency>
    
        <dependency>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis-spring</artifactId>
          <version>1.3.1</version>
        </dependency>
    
        <dependency>
          <groupId>com.alibaba</groupId>
          <artifactId>druid</artifactId>
          <version>1.1.6</version>
        </dependency>
    
        <!--logback好的日志-->
        <dependency>
          <groupId>ch.qos.logback</groupId>
          <artifactId>logback-classic</artifactId>
          <version>1.2.3</version>
        </dependency>
        <dependency>
          <groupId>org.logback-extensions</groupId>
          <artifactId>logback-ext-spring</artifactId>
          <version>0.1.4</version>
        </dependency>
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>jcl-over-slf4j</artifactId>
          <version>1.7.25</version>
        </dependency>
    
    
        <!--数据库-->
        <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <version>6.0.6</version>
        </dependency>
        <dependency>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis</artifactId>
          <version>3.4.5</version>
        </dependency>
    
        <dependency>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis-spring</artifactId>
          <version>1.3.1</version>
        </dependency>
    
        <dependency>
          <groupId>com.alibaba</groupId>
          <artifactId>druid</artifactId>
          <version>1.1.6</version>
        </dependency>
    
    
        <!-- 上传组件 -->
        <dependency>
          <groupId>commons-fileupload</groupId>
          <artifactId>commons-fileupload</artifactId>
          <version>1.3.3</version>
        </dependency>
    
    
    
        <!--fastjson序列化-->
        <dependency>
          <groupId>com.alibaba</groupId>
          <artifactId>fastjson</artifactId>
          <version>1.2.46</version>
        </dependency>
        <!-- 或jackjson -->
        <dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-core</artifactId>
          <version>2.9.4</version>
        </dependency>
        
        <dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-databind</artifactId>
          <version>2.9.4</version>
        </dependency>
    
    
        <dependency>
          <groupId>org.apache.httpcomponents</groupId>
          <artifactId>httpcore</artifactId>
          <version>4.4.5</version>
        </dependency>
    
        <dependency>
          <groupId>org.apache.httpcomponents</groupId>
          <artifactId>httpclient</artifactId>
          <version>4.5.2</version>
        </dependency>
    

      在build节点内加入:

    <plugins>
    
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
              <encoding>${project.build.sourceEncoding}</encoding>
            </configuration>
          </plugin>
    
          <!--jetty-->
          <plugin>
            <!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-maven-plugin -->
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.3.23.v20180228</version>
    
    
            <configuration>
              <scanIntervalSeconds>3</scanIntervalSeconds>
              <httpConnector>
                <port>8088</port>
              </httpConnector>
            </configuration>
          </plugin>
    
          <plugin>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-maven-plugin</artifactId>
            <version>1.3.5</version>
            <dependencies>
              <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.26</version>
              </dependency>
            </dependencies>
    
            <configuration>
              <!-- 危险 小心使用 -->
              <overwrite>true</overwrite>
            </configuration>
    
          </plugin>
    
    
        </plugins>
    

      根据我的项目结构目录,此处需要在<build></build>节点加入如下代码:

    <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>
    

      

    至此pom.xml文件配置完毕,如果使用tomcat而不是使用jetty,可不配置jetty插件;

    然后在resources文件夹中拷入建立,配置如下文件:

    接下来进行web.xml:

    <!--定义spring配置文件-->
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
          classpath*:applicationContext.xml
        </param-value>
      </context-param>
    
      <!--定义监听器,监听servlet容器启动成功事件,启动成功后加载spring上下文
      说明:通过contextConfigLocation全局变量来定位application.xml-->
      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
    
      <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-servlet.xml</param-value>
        </init-param>
         <load-on-startup>1</load-on-startup>
      </servlet>
    
      <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
      </servlet-mapping>
    

      web.xml配置完毕;

    在...中写入如下代码:

    启动服务器前 ,检查有没有红色代码,如果有,说明可能有问题,需要改;

    启动服务器,启动完成没有报错时;

    这个{[xxx]}说明启动成功,无错误

    浏览器输入:

    localhost:8088

    回车访问:

     

    出现上述界面,说明正ssm常访问,一切正常,至此ssm项目框架搭建完毕。

    【声明】转载注明链接,源码联系公众号:aandb7获取~

  • 相关阅读:
    说一下Mysql索引
    B树、B-树、B+树、B*树之间的关系
    Mybatis Plus 的优点
    JVM垃圾回收机制
    Java中的集合
    MQ 面试题
    Redis 双写一致性
    Redis 主从复制
    C#中Abstract和Virtual的区别
    C#设计模式(2)——简单工厂模式
  • 原文地址:https://www.cnblogs.com/m-yb/p/8624167.html
Copyright © 2020-2023  润新知