1. 程式人生 > >IDEA建立maven專案 整合SSM框架

IDEA建立maven專案 整合SSM框架

IDEA整合SSM框架

記錄下自己用idea來搭建SSM框架的步驟。為新手指指路,也為自己留個後路!

建立maven專案

由於ssm框架有很多jar包需要匯入,因此我們選擇用maven來管理專案。如果有不會建立maven專案的同學,請參考我的這篇文章 : IDEA建立maven專案

編寫pom.xml檔案

網上整合出的pom檔案程式碼有很多,新手可以不必自己一個個收集jar包。
這裡直接放出完整的程式碼,內涵註釋,先不多做解釋~直接替換都行!
貼上完以後,記得點import changes哦!
然後趕緊做下一步,別傻等著jar下完~人生很短暫!且打程式碼且珍惜!

<projectxmlns="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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>cn.asghoul</groupId>
  <artifactId>ssm</
artifactId>
<packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>ssm Maven Webapp</name> <url>http://maven.apache.org</url> <properties> <!-- 設定專案編碼編碼 --> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding
>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <!-- spring版本號 --> <spring.version>4.3.5.RELEASE</spring.version> <!-- mybatis版本號 --> <mybatis.version>3.4.1</mybatis.version> <!-- jstl版本號 --> <jstl.version>1.2</jstl.version> </properties> <dependencies> <!-- java ee --> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> </dependency> <!-- 單元測試 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <!-- 實現slf4j介面並整合 --> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.2</version> </dependency> <!-- JSON --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.8.7</version> </dependency> <!-- 資料庫 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.41</version> <scope>runtime</scope> </dependency> <!-- 資料庫連線池 --> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.5.2</version> </dependency> <!-- MyBatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <!-- mybatis/spring整合包 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.3.1</version> </dependency> <!-- Spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</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-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-web</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-test</artifactId> <version>${spring.version}</version> </dependency> <!-- JSP相關 --> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>${jstl.version}</version> </dependency> </dependencies> <build> <finalName>ssm</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <!-- 設定JDK版本 --> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> </project>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145

建立專案架構

先按照我給的圖建立好專案結構。

ssm專案架構

專案架構說明

差不多是一個標準ssm的專案架構,架構說明這塊寫的有誤的地方請大家指正!

目錄名 說明
controller 控制器,寫介面的地方
dao 資料互動層
pojo 模型層,放物件,也是mvc中的model層
service 業務邏輯層
impl 業務實現層
utils 存放工具類
mapper mybatis裡呼叫的sql的xml
sql 可以存放被多次呼叫的相同的sql語句
jdbc.properties 連線資料庫的配置檔案
log4j.properties 配置log的檔案
spring-mvc.xml 配置springmvc的檔案
spring-mybatis.xml 配置spring和mybatis的檔案

配置各檔案

這部分大家酌情修改,主要修改包名,資料庫連線資訊。

jdbc.properties

jdbc.driver=com.mysql.jdbc.Driver
#資料庫地址
jdbc.url=jdbc:mysql://localhost:3306/ssm?useUnicode=true&characterEncoding=utf8
#使用者名稱
jdbc.username=root
#密碼
jdbc.password=123456
#最大連線數
c3p0.maxPoolSize=30
#最小連線數
c3p0.minPoolSize=10
#關閉連線後不自動commit
c3p0.autoCommitOnClose=false
#獲取連線超時時間
c3p0.checkoutTimeout=10000
#當獲取連線失敗重試次數
c3p0.acquireRetryAttempts=2
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

log4j.properties

<?xml version="1.0" encoding="UTF-8"?>
<configurationdebug="true">
<appendername="STDOUT"class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<rootlevel="debug">
<appender-refref="STDOUT"/>
</root>
</configuration>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

spring-mvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"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.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <!-- 掃描web相關的bean -->
    <context:component-scanbase-package="cn.asghoul.controller"/>

    <!-- 開啟SpringMVC註解模式 -->
    <mvc:annotation-driven/>

    <!-- 靜態資源預設servlet配置 -->
    <mvc:default-servlet-handler/>

    <!-- 配置jsp 顯示ViewResolver -->
    <beanclass="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <propertyname="viewClass"value="org.springframework.web.servlet.view.JstlView"/>
        <propertyname="prefix"value="/views/"/>
        <propertyname="suffix"value=".jsp"/>
    </bean>

</beans>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

spring-mybatis.xml

<?xml version="1.0" encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!-- 掃描service包下所有使用註解的型別 -->
    <context:component-scanbase-package="cn.asghoul.service"/>

    <!-- 配置資料庫相關引數properties的屬性:${url} -->
    <context:property-placeholderlocation="classpath:jdbc.properties"/>

    <!-- 資料庫連線池 -->
    <beanid="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <propertyname="driverClass"value="${jdbc.driver}"/>
        <propertyname="jdbcUrl"value="${jdbc.url}"/>
        <propertyname="user"value
            
           

相關推薦

IDEA建立maven專案 整合SSM框架

IDEA整合SSM框架 記錄下自己用idea來搭建SSM框架的步驟。為新手指指路,也為自己留個後路! 建立maven專案 由於ssm框架有很多jar包需要匯入,因此我們選擇用maven來管理專案。如果有不會建立maven專案的同學,請參考我的這篇文章 : IDEA建立maven專案

SSM】Eclipse使用Maven建立Web專案+整合SSM框架

       自己接觸ssm框架有一段時間了,從最早的接觸新版ITOO專案的(SSM/H+Dobbu zk),再到自己近期來學習到的《淘淘商城》一個ssm框架的電商專案。用過,但是還真的沒有自己搭建過,一直都是用別人搭建好的。所以,從網上找了一些材料,結合自己來解決過程

通過idea建立Maven專案整合Spring+spring mvc+mybatis

寫這篇文章是為了整理一下idea下整合maven專案的步驟,也為了以後讓室友們參考 建立專案 File→new→project        

eclipse maven專案整合SSM框架(親測有效)

本文蒐集了網上的很多資料,整理得來,版權歸相關作者所有 首先 maven的配置 請自行百度,本文預設一切環境都搭建完畢,只是需要完整的專案構建與SSM框架整合流程 當你解決完上述問題後,你的專案應該完成整合了。

使用Eclipse 建立maven專案搭建ssm框架

一:整體專案結構圖二:建立maven專案三:pom.xml配置<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

MyEclipse使用Maven建立web專案+搭建SSM框架教程

使用maven已經有一段時間了,但專案是別人搭建好的,因此一直想著自己要學習搭建一下。網上找了些資料後,結合自己的實驗,花了點時間就搞好了,老樣子,寫在部落格上,免得日後忘記。 安裝maven和配置 1、下載maven.apache.org/downl

1106_解決IntelliJ IDEA 建立Maven專案速度慢問題 archetypeCatalog

解決IntelliJ IDEA 建立Maven專案速度慢問題 DarchetypeCatalog 原因 IDEA根據maven archetype的本質,其實是執行mvn archetype:generate命令,該命令執行時,需要指定一個archetype-catalog.xml檔案。

詳述 IntelliJ IDEA 建立 Maven 專案及設定 java 源目錄的方法

Maven 是一個優秀的專案管理工具,它為我們提供了一個構建完整的生命週期框架。現在,就讓我們一起看看如何利用 IntelliJ IDEA 快速的建立 Maven 專案吧! 如上圖所示,點選Create New Project: 標註 1:Maven選項; 標註

使用 IDEA 建立 maven 專案

文章目錄 第一步 第二步 第三步 目錄結構的設定 第一步 點選 maven ; 勾選從模板建立 ; 選擇 webapp ; 第二步 第三步

idea 建立maven 專案無src專案結構解決辦法

1、遇見問題 建立Maven專案時,maven專案無法出現src的目錄結構,如圖所示。 2、網上的解決方案 在網上找到一些資料,發現要到,settings-maven-runner中配置-DarchetypeCatalog=internal 3 、

解決IntelliJ IDEA 建立Maven專案速度慢問題

原因 IDEA根據maven archetype的本質,其實是執行mvn archetype:generate命令,該命令執行時,需要指定一個archetype-catalog.xml檔案。 該命令的引數-DarchetypeCatalog,可選值為:remote,i

解決IntelliJ IDEA 建立Maven專案速度慢的方法

解決IntelliJ IDEA 建立Maven專案速度慢有兩種方法: 指定虛擬機器引數:DarchetypeCatalog 建立專案的時候新增引數:archetypeCatalog archetypeCatalog 和 DarchetypeCatalog 有三個屬

idea建立maven專案沒有webapp目錄

在學習spring時,建立的maven專案沒有webapp目錄。 由於maven是最基本的專案,只包含pom.xml,我們若想建立的是web專案 須選擇maven基本的web包 這裡選中maven基本的webapp包即可

用Intellij Idea建立maven專案 web專案

用intellij idea 建立一個Java web專案 1,file,new project,後,按下圖進行操作 彈出如下圖,並按下圖內容輸入,其中,groupId好比是google公司,artifactId好比是google出的一個產品,version就不多說了。

Idea建立Maven專案沒有src

由於是第一次建立,下載非常慢,解決方法: 一、新增 -DarchetypeCatalog=internal 引數 二、建立Maven專案時加上 archetypeCatalog=internal 引數 效果如下

idea建立 maven專案

如果是第一次建立Maven專案,專案因為載入jar會導致啟動有點慢,專案載入成功後會顯示 目錄結構 新增目錄 右鍵main建立java、test、resources目錄,並分別將3個目錄設定成source、test、resources型別

idea 建立maven專案

使用idea建立maven專案的主要步驟。 一、開啟idea在裡面找到Create New Project,如下圖: 二、點選建立新專案之後,左側找到Maven ,右側將Create from archetype打鉤,然後選擇maven下webapp包如

ideamaven專案搭建mybatis框架

    第一步: 先建立一個maven專案,詳細步驟就不多說了          第二步: 在搭建好的maven專案中開啟pom.xml,載入所需的jar包,配置如下: <project xmlns="http://maven.apache.org/POM/4.0.

IDEA建立maven專案詳細步驟

一,maven配置File > settings > Bulid..(快捷鍵 Ctrl + Alt + S) 顯示maven預設的配置,可以修改,也可以用預設的我修改為自己的:修改後點選ok

IntelliJ IDEA 建立maven專案

1、開啟IntelliJ IDEA——>Create new Project    2、選擇maven 和 jdk 然後單擊“next”   3、輸入包名和專案名字   Groupid 是包名  ArtifactId是不含版本號的jar包名字 例如我這裡輸入“com