Java basic tutorial-use IDEA to create a Maven-style SSM project

Java zero-based self-study website, click to understand: https://how2j.cn

Aliyun server, click to learn: https://www.aliyun.com/minisite/goods

table of Contents

Step 1: IDEA version

Step 2: Based on the previous knowledge points

Step 3: Create a new project

Step 4: Select the maven webapp format

Step 5: project parameters

Step 6: Confirm Maven path

Step 7: Confirm the project name

Step 8: Maven import

Step 9: Create a new java source code directory

Step 10: download the project and unzip

Step 11: modify pom.xml

Step 12: Copy web.xml

Step 13: Copy JSP

Step 14: Copy the resource file

Step 15: Copy the java file

Step 16: About Category.xml

Step 17: configure Tomcat

Step 18: start Tomcat

Step 19: test


Step 1: IDEA version

Note:  IDEA must use  IDEA 2017. The 2018 version has a bug and cannot deploy this project.
If you must use idea 2018, you need to make the following changes:
File->Settings->Build,Execution,Deployment->Build Tools->Maven->Importing  Cancel  "Store generated project files externally"
so that it can be used

Step 2: Based on the previous knowledge points

This knowledge point is carried out on the basis of PageHelper , so first go to PageHelper to download the executable project and unzip it.

Note:  Do not download to the runnable project of the current knowledge point.

Step 3: Create a new project

Click Create New Project to create a new project

New Project

Step 4: Select the maven webapp format

1. Select Maven on the left
2. Check Create from archetype
3. Select org.apache.maven.archetypes:maven-archetype-webapp
4. Next

Select the maven webapp format

Step 5: project parameters

GroupId: com.how2java
ArtifactId: ssm

Project parameters

Step 6: Confirm Maven path

This step will see the parameters in the Maven configuration , no need to change

Confirm Maven path

Step 7: Confirm the project name

No need to change, just click Finish

Confirm project name

Step 8: Maven import

Every time a new Maven project is created or pom.xml is changed, there will be this prompt. This time, click Enable Auto-Import to automatically import, saving trouble.

Maven import

Step 9: Create a new java source code directory

The maven web project does not have a java source code directory by default, so you need to create it manually and set it as the source code directory.
Right-click the main directory -> New->Directory-> enter java-> right-click java->Mark Directory as-> Sources Root
This creates a directory for storing java source files

Create a new java source code directory

Step 10: download the project and unzip

This knowledge point is carried out on the basis of PageHelper , so first go to PageHelper to download the executable project and unzip it.

As shown in the figure, what you see is the directory structure of the Eclipse dynamic web project.

Note:  Do not download to the runnable project of the current knowledge point.

Download the project and unzip

import java.io.IOException;

import java.util.Date;

  

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

  

public class HelloServlet extends HttpServlet{

  

    public void doGet(HttpServletRequest request, HttpServletResponse response){

          

        try {

            response.getWriter().println("<h1>Hello Servlet!</h1>");

            response.getWriter().println(new Date().toLocaleString());

        catch (IOException e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

        }

    }

      

}

Step 11: modify pom.xml

Then copy and paste pom.xml as the following code

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.how2java</groupId>

  <artifactId>ssm</artifactId>

  <version>0.0.1-SNAPSHOT</version>

  <packaging>war</packaging>

  

  <properties>

    <spring.version>4.1.3.RELEASE</spring.version>

    <pagehelper.version>5.1.2-beta</pagehelper.version>

    <mysql.version>5.1.6</mysql.version>

    <mybatis.spring.version>1.2.3</mybatis.spring.version>

    <mybatis.version>3.1.1</mybatis.version>

    <junit.version>4.12</junit.version>

    <jstl.version>1.2</jstl.version>

    <jsqlparser.version>1.0</jsqlparser.version>

    <jackson.version>1.2.7</jackson.version>

    <servlet-api.version>3.1.0</servlet-api.version>

    <druid.version>1.0.18</druid.version>

    <log4j.version>1.2.16</log4j.version>

    <commons-logging.version>1.2</commons-logging.version>

    <commons-fileupload.version>1.2.1</commons-fileupload.version>

    <commons-io.version>1.3.2</commons-io.version>

    <commons-lang.version>2.6</commons-lang.version>

    <aopalliance.version>1.0</aopalliance.version>

    <mybatis-generator.version>1.3.5</mybatis-generator.version>

  </properties>

  

  <dependencies>

  

    <dependency>

      <groupId>junit</groupId>

      <artifactId>junit</artifactId>

      <version>${junit.version}</version>

    </dependency>

  

    <dependency>

      <groupId>org.mybatis</groupId>

      <artifactId>mybatis</artifactId>

      <version>${mybatis.version}</version>

    </dependency>

  

    <dependency>

      <groupId>org.mybatis</groupId>

      <artifactId>mybatis-spring</artifactId>

      <version>${mybatis.spring.version}</version>

    </dependency>

  

    <dependency>

      <groupId>mysql</groupId>

      <artifactId>mysql-connector-java</artifactId>

      <version>${mysql.version}</version>

    </dependency>

  

    <dependency>

      <groupId>com.alibaba</groupId>

      <artifactId>druid</artifactId>

      <version>${druid.version}</version>

    </dependency>

  

    <dependency>

      <groupId>org.springframework</groupId>

      <artifactId>spring-context</artifactId>

      <version>${spring.version}</version>

    </dependency>

  

    <dependency>

      <groupId>org.springframework</groupId>

      <artifactId>spring-test</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-webmvc</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-aspects</artifactId>

      <version>${spring.version}</version>

    </dependency>

    <!-- JSP相关 -->

    <dependency>

      <groupId>jstl</groupId>

      <artifactId>jstl</artifactId>

      <version>${jstl.version}</version>

    </dependency>

  

    <dependency>

      <groupId>javax.servlet</groupId>

      <artifactId>javax.servlet-api</artifactId>

      <version>${servlet-api.version}</version>

      <scope>provided</scope>

    </dependency>

  

    <!-- pageHelper -->

    <dependency>

      <groupId>com.github.pagehelper</groupId>

      <artifactId>pagehelper</artifactId>

      <version>${pagehelper.version}</version>

    </dependency>

  

    <!--jsqlparser-->

    <dependency>

      <groupId>com.github.jsqlparser</groupId>

      <artifactId>jsqlparser</artifactId>

      <version>${jsqlparser.version}</version>

    </dependency>

    <dependency>

      <groupId>log4j</groupId>

      <artifactId>log4j</artifactId>

      <version>${log4j.version}</version>

    </dependency>

  

    <dependency>

      <groupId>commons-logging</groupId>

      <artifactId>commons-logging</artifactId>

      <version>${commons-logging.version}</version>

    </dependency>

  

    <dependency>

      <groupId>commons-fileupload</groupId>

      <artifactId>commons-fileupload</artifactId>

      <version>${commons-fileupload.version}</version>

    </dependency>

  

    <dependency>

      <groupId>commons-io</groupId>

      <artifactId>commons-io</artifactId>

      <version>${commons-io.version}</version>

    </dependency>

  

    <dependency>

      <groupId>commons-lang</groupId>

      <artifactId>commons-lang</artifactId>

      <version>${commons-lang.version}</version>

    </dependency>

  

    <dependency>

      <groupId>aopalliance</groupId>

      <artifactId>aopalliance</artifactId>

      <version>${aopalliance.version}</version>

    </dependency>

  

    <dependency>

      <groupId>org.mybatis.generator</groupId>

      <artifactId>mybatis-generator-core</artifactId>

      <version>${mybatis-generator.version}</version>

    </dependency>

  

  </dependencies>

  

  <build>

    <finalName>${project.artifactId}</finalName>

    <plugins>

      <!-- 资源文件拷贝插件 -->

      <plugin>

        <groupId>org.apache.maven.plugins</groupId>

        <artifactId>maven-resources-plugin</artifactId>

        <version>2.7</version>

        <configuration>

          <encoding>UTF-8</encoding>

        </configuration>

      </plugin>

      <!-- java编译插件 -->

      <plugin>

        <groupId>org.apache.maven.plugins</groupId>

        <artifactId>maven-compiler-plugin</artifactId>

        <version>3.2</version>

        <configuration>

          <source>1.8</source>

          <target>1.8</target>

          <encoding>UTF-8</encoding>

        </configuration>

      </plugin>

    </plugins>

    <pluginManagement>

      <plugins>

        <!-- 配置Tomcat插件 -->

        <plugin>

          <groupId>org.apache.tomcat.maven</groupId>

          <artifactId>tomcat7-maven-plugin</artifactId>

          <version>2.2</version>

        </plugin>

      </plugins>

    </pluginManagement>

  

    <resources>

      <resource>

        <directory>src/main/resources</directory>

        <includes>

          <include>**/*.properties</include>

          <include>**/*.xml</include>

          <include>**/*.tld</include>

        </includes>

        <filtering>false</filtering>

      </resource>

      <resource>

        <directory>src/main/java</directory>

        <includes>

          <include>**/*.properties</include>

          <include>**/*.xml</include>

        </includes>

        <filtering>false</filtering>

      </resource>

    </resources>

  

  </build>

  

</project>

Step 12: Copy web.xml

First overwrite web.xml and
copy the downloaded xxx/ssm/WebContent/WEB-INF/web.xml
to the current ssm/src/main/webapp/web.xml

Copy web.xml

Step 13: Copy JSP

Then copy the jsp directory.
Never copy the lib directory

Copy JSP

Step 14: Copy the resource file

Copy the 3 configuration files to ssm/src/main/resources

Copy resource file

Step 15: Copy the java file

Copy the java source code to src/main/java

Copy java file

Step 16: About Category.xml

According to the maven ssm project style, this file should be placed in the mapper folder of the Resource directory, but to do so, the configuration information must be modified, in order to avoid the complexity of the problem, and considering that it can work even if it is placed in the current location , So I won’t modify its position temporarily.

About Category.xml

Step 17: configure Tomcat

Tomcat configuration and startup involve multiple steps, please refer to the previous article specifically for IDEA:  Configure Tomcat

Configure Tomcat

Step 18: start Tomcat

Click the green button to start Tomcat

Start Tomcat

Step 19: test

Visit the address and observe the interface as shown in the figure

http://localhost:8080/ssm/listCategory



Note:  In order to use ssm in the access path, you must set the Application context/ of the Deployment of the Tomcat configuration interface to ssm, otherwise you can only use the following path to access

http://localhost:8080/listCategory

test


For more information, click to understand:  https://how2j.cn/k/idea/idea-maven-idea-ssm-create/1397.html

Guess you like

Origin blog.csdn.net/java_zdc/article/details/105848635