IDEA搭建Maven风格的SSM项目框架

IDEA + Maven搭建SSM项目框架

  • IDEA版本:2017.1

  • 源代码在如下链接

  • 本文基于How2j网站的SSM学习教程[http://how2j.cn/k/idea/idea-maven-idea-ssm-import/1398.html]

  • 建议Maven配置国内仓库,不然加载时间够吃一顿饭

1. 创建新Maven项目:

  • 新建一个Maven项目,不要勾选使用模板

IDEA搭建Maven风格的SSM项目框架_第1张图片

  • 填写各种信息

IDEA搭建Maven风格的SSM项目框架_第2张图片

  • 下一步

IDEA搭建Maven风格的SSM项目框架_第3张图片

  • 点击finish ; 这里点一下Enable-Auto-import

IDEA搭建Maven风格的SSM项目框架_第4张图片

这样一个Maven项目就创建完成了, 此时这个项目还不是Web项目

2. 为项目添加Web模组

  • Ctrl Alt Shift S 或者如下点开项目设置

IDEA搭建Maven风格的SSM项目框架_第5张图片

  • 进入Modules发现这个只是个普通项目,添加Web组件

IDEA搭建Maven风格的SSM项目框架_第6张图片

  • 添加完成后修改web目录到main文件夹下, 点击箭头指的地方

IDEA搭建Maven风格的SSM项目框架_第7张图片
IDEA搭建Maven风格的SSM项目框架_第8张图片
IDEA搭建Maven风格的SSM项目框架_第9张图片
IDEA搭建Maven风格的SSM项目框架_第10张图片
IDEA搭建Maven风格的SSM项目框架_第11张图片

  • 接下来配置输出

IDEA搭建Maven风格的SSM项目框架_第12张图片
IDEA搭建Maven风格的SSM项目框架_第13张图片

  • 配置完成后不要忘了点OK

IDEA搭建Maven风格的SSM项目框架_第14张图片

  • 此时的项目结构

IDEA搭建Maven风格的SSM项目框架_第15张图片

3. 配置Tomcat

IDEA搭建Maven风格的SSM项目框架_第16张图片
IDEA搭建Maven风格的SSM项目框架_第17张图片
IDEA搭建Maven风格的SSM项目框架_第18张图片

  • 吧项目添加进tomcat里

IDEA搭建Maven风格的SSM项目框架_第19张图片
IDEA搭建Maven风格的SSM项目框架_第20张图片

4. 配置pom.xml


<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.0modelVersion>

    <groupId>com.how2javagroupId>
    <artifactId>ssmartifactId>
    <version>1.0-SNAPSHOTversion>

    <properties>
        <spring.version>4.1.3.RELEASEspring.version>
        <pagehelper.version>5.1.2-betapagehelper.version>
        <mysql.version>5.1.6mysql.version>
        <mybatis.spring.version>1.2.3mybatis.spring.version>
        <mybatis.version>3.1.1mybatis.version>
        <junit.version>4.12junit.version>
        <jstl.version>1.2jstl.version>
        <jsqlparser.version>1.0jsqlparser.version>
        <jackson.version>1.2.7jackson.version>
        <servlet-api.version>3.1.0servlet-api.version>
        <druid.version>1.0.18druid.version>
        <log4j.version>1.2.16log4j.version>
        <commons-logging.version>1.2commons-logging.version>
        <commons-fileupload.version>1.2.1commons-fileupload.version>
        <commons-io.version>1.3.2commons-io.version>
        <commons-lang.version>2.6commons-lang.version>
        <aopalliance.version>1.0aopalliance.version>
        <mybatis-generator.version>1.3.5mybatis-generator.version>
    properties>

    <dependencies>

        <dependency>
            <groupId>junitgroupId>
            <artifactId>junitartifactId>
            <version>${junit.version}version>
        dependency>


        <dependency>
            <groupId>org.mybatisgroupId>
            <artifactId>mybatisartifactId>
            <version>${mybatis.version}version>
        dependency>

        <dependency>
            <groupId>org.mybatisgroupId>
            <artifactId>mybatis-springartifactId>
            <version>${mybatis.spring.version}version>
        dependency>

        <dependency>
            <groupId>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
            <version>${mysql.version}version>
        dependency>

        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>druidartifactId>
            <version>${druid.version}version>
        dependency>

        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-contextartifactId>
            <version>${spring.version}version>
        dependency>

        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-testartifactId>
            <version>${spring.version}version>
        dependency>


        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-beansartifactId>
            <version>${spring.version}version>
        dependency>

        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-webmvcartifactId>
            <version>${spring.version}version>
        dependency>

        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-jdbcartifactId>
            <version>${spring.version}version>
        dependency>

        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-aspectsartifactId>
            <version>${spring.version}version>
        dependency>
        
        <dependency>
            <groupId>jstlgroupId>
            <artifactId>jstlartifactId>
            <version>${jstl.version}version>
        dependency>

        <dependency>
            <groupId>javax.servletgroupId>
            <artifactId>javax.servlet-apiartifactId>
            <version>${servlet-api.version}version>
            <scope>providedscope>
        dependency>

        
        <dependency>
            <groupId>com.github.pagehelpergroupId>
            <artifactId>pagehelperartifactId>
            <version>${pagehelper.version}version>
        dependency>

        
        <dependency>
            <groupId>com.github.jsqlparsergroupId>
            <artifactId>jsqlparserartifactId>
            <version>${jsqlparser.version}version>
        dependency>
        <dependency>
            <groupId>log4jgroupId>
            <artifactId>log4jartifactId>
            <version>${log4j.version}version>
        dependency>

        <dependency>
            <groupId>commons-logginggroupId>
            <artifactId>commons-loggingartifactId>
            <version>${commons-logging.version}version>
        dependency>

        <dependency>
            <groupId>commons-fileuploadgroupId>
            <artifactId>commons-fileuploadartifactId>
            <version>${commons-fileupload.version}version>
        dependency>

        <dependency>
            <groupId>commons-iogroupId>
            <artifactId>commons-ioartifactId>
            <version>${commons-io.version}version>
        dependency>

        <dependency>
            <groupId>commons-langgroupId>
            <artifactId>commons-langartifactId>
            <version>${commons-lang.version}version>
        dependency>

        <dependency>
            <groupId>aopalliancegroupId>
            <artifactId>aopallianceartifactId>
            <version>${aopalliance.version}version>
        dependency>

        <dependency>
            <groupId>org.mybatis.generatorgroupId>
            <artifactId>mybatis-generator-coreartifactId>
            <version>${mybatis-generator.version}version>
        dependency>


    dependencies>

    <build>
        <finalName>${project.artifactId}finalName>
        <plugins>
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-resources-pluginartifactId>
                <version>2.7version>
                <configuration>
                    <encoding>UTF-8encoding>
                configuration>
            plugin>
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <version>3.2version>
                <configuration>
                    <source>1.8source>
                    <target>1.8target>
                    <encoding>UTF-8encoding>
                configuration>
            plugin>
        plugins>
        <pluginManagement>
            <plugins>
                
                <plugin>
                    <groupId>org.apache.tomcat.mavengroupId>
                    <artifactId>tomcat7-maven-pluginartifactId>
                    <version>2.2version>
                plugin>
            plugins>
        pluginManagement>

        <resources>
            <resource>
                <directory>src/main/resourcesdirectory>
                <includes>
                    <include>**/*.propertiesinclude>
                    <include>**/*.xmlinclude>
                    <include>**/*.tldinclude>
                includes>
                <filtering>falsefiltering>
            resource>
            <resource>
                <directory>src/main/javadirectory>
                <includes>
                    <include>**/*.propertiesinclude>
                    <include>**/*.xmlinclude>
                includes>
                <filtering>falsefiltering>
            resource>
        resources>

    build>


project>

5. 创建数据库

  • 创建数据库:how2java
create database how2java;
  • 创建表:
DROP TABLE IF EXISTS `category_`;
CREATE TABLE `category_` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
  • 导入测试数据
INSERT INTO `category_` VALUES ('1', 'category1');
INSERT INTO `category_` VALUES ('2', 'category2');
INSERT INTO `category_` VALUES ('3', 'category3');
INSERT INTO `category_` VALUES ('4', 'category4');
INSERT INTO `category_` VALUES ('5', 'category5');

6. 编写各种文件

  1. 下载上面的链接中的文件, 复制粘贴
  2. 修改applicationContext中的数据库连接密码为自己的
  3. 启动tomcat运行

  • 如果失败就直接按照链接中教程所示直接导入该项目再配置tomcat运行

你可能感兴趣的:(读书笔记)