使用idea搭建spring+maven+mybatis项目框架

本文介绍了使用IntelliJ IDEA搭建Spring+Maven+Mybatis项目框架的步骤,包括创建Maven Webapp项目、配置目录结构、设置配置文件以及编写代码。在搭建过程中提到了可能遇到的问题,如Maven仓库连接问题、配置错误等,并提供了解决方案。建议使用Spring Boot进行项目搭建,以简化配置。
摘要由CSDN通过智能技术生成

先说一句,这个是spring+maven+mybatis项目框架的搭建文章。

强烈推荐大家使用springboot搭建项目,搭建过程会轻松很多,减少很多解决配置问题的时间。

详情请移步:使用springboot搭建maven+mybatis视频讲解

 

以下是使用idea搭建spring+maven+mybatis项目框架 正文:

 

需要准备的环境:

  idea ,jdk1.8,Maven 3.2.3(我自己的可能比较老,建议下载相对新的版本),mysql-8.0.17(需最低jdk1.8),MYSQLworkbench

     提前将idea与Maven、jdk配置好。注:配置完ide红线报错没关系!可以run。

 

一、首先使用idea新建一个Maven webapp项目

  

  

  

点击下一步,Finish,空项目搭建完成。

 

二、搭建目录结构

  这里列出的是搭建完了之后所有的目录和文件,先把目录文件建起来:

  

  这里的目录建好之后还需要设置一下,让idea识别目录作用,选择File-Project Structure,设置方法如图:

  

 

 

三、配置文件内容

  • pom.xml

pom里使用的版本与自身配置需要对应。如果没有1.8jdk建议安装,否则容易和很多新版的应用不兼容。

<?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>gloria.learn</groupId>
    <artifactId>SpringLearn</artifactId>
    <version>1.0-SNAPSHOT</version>

    <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>
    </properties>

      <repositories>
        <repository>
            <id>nexus-aliyun</id>
            <name>nexus-aliyun</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <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>8.0.17</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>
       
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值