為開發一個測驗程式,特搭建一個簡單的ssm框架,因為網上看到很多都是比較老舊的教程,很多包都不能用了,eclipes搭建并且其中還附帶了很多的其他東西,所以特此記錄一下idea中搭建ssm框架程序,
其實就是因為這不是疫情原因,家里好多親戚家得孩子提前放學了,但是有好幾個又面臨找作業得境地,真的是親戚多了費勁啊,一波波得,浪浪不絕啊,而且大學學的怎么樣,我想,不需要我說太多什么東西,哎,所以,沒辦法,只能給他們補課了,所以現在需要搭建這樣一套簡單的web框架,正好也回顧梳理一下自己的知識,鞏固一下基礎,看看年后有沒有機會跳一下啊,哈哈哈哈,一不小心透露內心最真實的想法
另:平常開發的專案中其實用的不是mybatis,而是mybatisplus,一款為簡化開發而生的基于mybatis的三方,只能說,用起來賊爽,省去了很多的sql陳述句,
關注公眾號:Java架構師聯盟,每日更新技術好文
以下為一步步操作,詳細可循,完全學習了白居易寫詩的風格,堪稱傻瓜教程,
目錄結構已建好的童鞋,可以直接跳過前幾步去看相應組態檔,點擊穿越,今天得內容以基礎內容搭建為基礎,適合新手觀看
一、搭建背景及準備條件
不是必須的,保證專案運行只要有這些東西就行,可以不一樣
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檔案,方便后面用來測驗
<%--
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>
\3. 現在基本目錄結構已建成,讓我們對比一下看是不是一樣的
4、 添加專案打包方式
1、file -> Project Structure -> Artifacts
因為之前已經將專案添加到Modules模塊中,所以這里可以直接顯示,直接ok即可
最終想要得到的結果如下圖:
到這里,基本就設計完成了
四、初步配置啟動tomcat服務
添加tomcat,進行相關配置 點擊面板右上角
添加配置tomcat
添加剛才生成的包
運行tomcat 右上角面板選擇debug模式運行(也可以普通模式)
運行成功,頁面顯示默認生成的index.jsp的內容 http://localhost:8075/
到這里,通過idea搭建一個完整得web專案開發環境就可以了,
后面我所有web相關得內容都會在這個專案的基礎上進行更新和修改,就像我前面說的,這些東西本就是基礎,而現在很多時候也需要原始碼、基礎等知識考察你的基本功扎實不扎實,那這個時候,放棄一些花里胡哨得東西,反而會更加有效果一些
這是我隨便寫了一個測驗的框架結構,相應得原始碼太多了,這里就先不對外發了,后面我會上傳到我的倉庫,有需要得朋友可以自己先試驗一下
我的pom檔案先給大家
<?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>
<!-- FIXME change it to the project's website -->
<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>
<!-- Spring最新的包 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<!--Spriing jdbc-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.7.4</version>
</dependency>
<!-- mysql連接 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
</dependency>
<!--資料庫連接池druid-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.11</version>
</dependency>
<!-- mybatis依賴 -->
<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>
<!-- json -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.0</version>
</dependency>
<!-- lombok插件通過@data注解 實作省略寫getset方法 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
</dependency>
<!-- json 包 fastjson -->
<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>
<!-- log日志 -->
<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>
<!--檔案上傳下載 commons-->
<!--<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.2</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>
<!-- 設定JDK版本 -->
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<fork>false</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
如果覺得檔案下載慢得話,可以去改一下下載源,我是改成了阿里得,相當不錯
找到你的maven安裝路徑
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
-->
</mirrors>
關注我,后面再持續更新呀
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/238866.html
標籤:Java
