使用IDEA創建一個SSM工程(非maven)


說在前面的話

直到現在從Eclipse向IDEA轉的人越來越多,但是IDEA的項目創建讓人摸不清頭腦,因此這里我創建一個非maven的ssm工程,供大家練練手,進一步的了解IDEA在項目中的使用。

創建項目

首先創建一個工程
在這里插入圖片描述
選擇java,圖中畫框框的多注意一下
在這里插入圖片描述
創建工程的名字 SSMProject01
在這里插入圖片描述
下面看一下原始的項目結構,很明顯和Eclipse創建的項目部太一樣,這里我們需要進行設置。
在這里插入圖片描述
下面我們在WEB-INF下創建lib和classes兩個文件夾,lib里存放jar包,classes里存放編譯的文件。
在這里插入圖片描述
把ssm需要的Jar包存放到lib中
在這里插入圖片描述
創建完兩個文件夾后我們再進行配置,也就是告訴編輯器lib和classes存放的位置。點擊快捷鍵Ctrl+Shift+Alt+S或者點擊圖中的快捷按鈕
在這里插入圖片描述
在這里插入圖片描述
接下來操作見圖:
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述

在src下創建一個IndexController.java文件
在這里插入圖片描述
在這里插入圖片描述
在WEB-INF下創建一個jsp文件夾,然后把index.jsp文件剪切過去。在這里插入圖片描述
編輯web.xml文件

<?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_4_0.xsd"
         version="4.0">
    <display-name>SSMProject01</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <!-- 加載spring容器 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext*.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- 解決post亂碼 -->
    <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>


    <!-- springmvc的前端控制器 -->
    <servlet>
        <servlet-name>SSMProject01</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- contextConfigLocation不是必須的, 如果不配置contextConfigLocation, springmvc的配置文件默認在:WEB-INF/servlet的name+"-servlet.xml" -->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>SSMProject01</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

在src下創建一個applicationContext.xml文件
在這里插入圖片描述
編輯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:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">

    <context:component-scan base-package="cn.tsu.xiaofeng" />
    <mvc:annotation-driven />
    <bean
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>

編輯index.jsp文件

<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/2/5 0005
  Time: 20:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>您好,歡迎來到IDEA</title>
  </head>
  <body>
 IDEA:您好${xiaofeng};
  </body>
</html>

下面開始配置Tomcat。
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
啟動tomcat
在這里插入圖片描述
在瀏覽器輸入http://localhost:8080/SSMProject01/gethtml
在這里插入圖片描述
ssm非maven工程搭建成功,若您在操作的過程中有任何疑問,歡迎留言!!

下一期給大家介紹IDEA搭建mavenSSM工程。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM