爲開發一個測試程序,特搭建一個簡單的ssm框架,因爲網上看到很多都是比較老舊的教程,很多包都不能用了,eclipes搭建並且其中還附帶了很多的其他東西,所以特此記錄一下idea中搭建ssm框架過程。
其實就是因爲這不是疫情原因,家裏好多親戚家得孩子提前放學了,但是有好幾個又面臨找工作得境地,真的是親戚多了費勁啊,一波波得,浪浪不絕啊,而且大學學的怎麼樣,我想,不需要我說太多什麼東西,哎,所以,沒辦法,只能給他們補課了,所以現在需要搭建這樣一套簡單的web框架,正好也回顧梳理一下自己的知識,鞏固一下基礎,看看年後有沒有機會跳一下啊,哈哈哈哈,一不小心透露內心最真實的想法
另:平常開發的項目中其實用的不是mybatis,而是mybatisplus,一款爲簡化開發而生的基於mybatis的三方,只能說,用起來賊爽,省去了很多的sql語句。
以下爲一步步操作,詳細可循,完全學習了白居易寫詩的風格,堪稱傻瓜教程。
目錄結構已建好的童鞋,可以直接跳過前幾步去看相應配置文件,點擊穿越,今天得內容以基礎內容搭建爲基礎,適合新手觀看
公衆號:Java架構師聯盟,後期會開放git倉庫地址
一、搭建背景及準備條件
不是必須的,保證項目運行只要有這些東西就行,可以不一樣
idea,maven3.6.0,jdk1.8,tomcat8,mysql5.7
二、搭建開始——新建項目
\1. file -> new -> project
\2. 新建maven項目,如圖勾選 create from archetype,並選擇 maven-archetype-webapp,next
\3. 選擇maven配置,選擇你自己的maven,next
同樣得,這裏可以設置文件下載位置,儘量不要下載到C盤,佔用空間
\4. 確定項目名,finish
完成項目結構目錄的創建,這裏需要耐心地等待一會兒,可以做點別的事情。
完成後結構目錄就會彈出(包含src等目錄),如果一直卡住不動,可以點擊右下方的import changes。
三、完善項目結構
\1. 新建java目錄 src/main/java
在這裏,idea就很友善,直接項目名上右鍵選擇創建新得Directory,可以針對一些必須的文件,直接創建,有四個選項,可以直接創建
2、 接下來,創建web模塊(我一直是這麼理解得,雖然咱也不知道對錯,或者說設置爲web項目),當完成這一步之後,會自動生成web文件夾
這兩個選項是設置你的web模塊路徑,我得就是默認得,如果你的路徑需要更改得話,這裏要改動,不然無法訪問
這是目錄,我們在其中創建index.jsp文件,方便後面用來測試
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" cid="n33532" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2020/12/19
Time: 22:19
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<p>歡迎光臨</p>
<h2>Hello World!</h2>
</body>
</html></pre>
\3. 現在基本目錄結構已建成,讓我們對比一下看是不是一樣的
4、 添加項目打包方式
1、file -> Project Structure -> Artifacts
因爲之前已經將項目添加到Modules模塊中,所以這裏可以直接顯示,直接ok即可
最終想要得到的結果如下圖:
到這裏,基本就設計完成了
四、初步配置啓動tomcat服務
添加tomcat,進行相關配置 點擊面板右上角
添加配置tomcat
添加剛纔生成的包
運行tomcat 右上角面板選擇debug模式運行(也可以普通模式)
運行成功,頁面顯示默認生成的index.jsp的內容 http://localhost:8075/
到這裏,通過idea搭建一個完整得web項目開發環境就可以了。
後面我所有web相關得內容都會在這個項目的基礎上進行更新和修改,就像我前面說的,這些東西本就是基礎,而現在很多時候也需要源碼、基礎等知識考察你的基本功紮實不紮實,那這個時候,放棄一些花裏胡哨得東西,反而會更加有效果一些
這是我隨便寫了一個測試的框架結構,相應得源碼太多了,這裏就先不對外發了,後面我會上傳到我的倉庫,有需要得朋友可以自己先試驗一下
我的pom文件先給大家
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" cid="n33569" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
<artifactId>WebCode</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>WebCode</name>
<url>http://www.example.com</url>
<properties>
<org.springframework.version>4.3.7.RELEASE</org.springframework.version>
<mybatis.version>3.5.0</mybatis.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>{org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.7.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.11</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.39</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>/.java</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>/.xml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<fork>false</fork>
</configuration>
</plugin>
</plugins>
</build>
</project></pre>
如果覺得文件下載慢得話,可以去改一下下載源,我是改成了阿里得,相當不錯
找到你的maven安裝路徑
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" cid="n33574" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> <mirrors>
</mirrors></pre>
關注我,後面再持續更新呀