
- 一、基本环境搭建
- 1、新建maven项目
- 2、导入依赖
- 3、maven资源过滤设置
- 4、建立基础包结构
- 5、配置框架
- 二、连接数据库
JDK:1.8
https://blog.csdn.net/qq_38509173/article/details/124678406
MySQL:5.7
https://blog.csdn.net/qq_38509173/article/details/108623510
TOMCAT:9.0
https://blog.csdn.net/qq_38509173/article/details/124717161
开发工具:IDEA
新建maven项目,并添加web支持。
显示这样的颜色,说明项目成功!
在pom.xml文件中添加依赖。一个SSM项目需要的基础依赖如下:
junit、数据库驱动、连接池、servlet、jsp、mybatis、mybatis-spring、spring 等。
maven仓库地址:https://mvnrepository.com/
将依赖copy到pom.xml
然后根据以上步骤,以此引入其他依赖。
注:mybatis用的3.5以上版本,且spring是5.0以上版本,则mybatis-spring要2.*版本的。
<dependencies>
<dependency>
<groupId>junitgroupId>
<artifactId>junitartifactId>
<version>4.12version>
<scope>testscope>
dependency>
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
<version>8.0.16version>
dependency>
<dependency>
<groupId>com.mchangegroupId>
<artifactId>c3p0artifactId>
<version>0.9.5.2version>
dependency>
<dependency>
<groupId>javax.servletgroupId>
<artifactId>servlet-apiartifactId>
<version>2.5version>
<scope>providedscope>
dependency>
<dependency>
<groupId>javax.servlet.jspgroupId>
<artifactId>jsp-apiartifactId>
<version>2.1version>
<scope>providedscope>
dependency>
<dependency>
<groupId>javax.servletgroupId>
<artifactId>jstlartifactId>
<version>1.2version>
dependency>
<dependency>
<groupId>org.mybatisgroupId>
<artifactId>mybatisartifactId>
<version>3.5.6version>
dependency>
<dependency>
<groupId>org.mybatisgroupId>
<artifactId>mybatis-springartifactId>
<version>2.0.6version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-webmvcartifactId>
<version>5.3.9version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-jdbcartifactId>
<version>5.3.9version>
dependency>
dependencies>
3、maven资源过滤设置
<build>
<resources>
<resource>
<directory>src/main/javadirectory>
<includes>
<include>**/*.propertiesinclude>
<include>**/*.xmlinclude>
includes>
<filtering>falsefiltering>
resource>
<resource>
<directory>src/main/resourcesdirectory>
<includes>
<include>**/*.propertiesinclude>
<include>**/*.xmlinclude>
includes>
<filtering>falsefiltering>
resource>
resources>
build>
注:进入File | Settings | Build, Execution, Deployment | Build Tools | Maven,设置maven home directory。
然后User settings file和Local repository也建议不要是默认的C盘下,分别调整为IDEA路径下的plugins下的maven,以及在其下建立一个repository文件夹,作为maven依赖包的下载位置,参考如下图:
完成后点击应用,确定。
改变了maven仓库的路径后,需要重新下载依赖包,如下图所示:
mybatis-config.xml
DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
configuration>
applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
beans>
然后applicationContext.xml文件上方会有提示需配置新建
默认,直接点击OK
database.properties
# 如果使用的MYSQL是8.0+,还需增加一个时区的配置 &serverTimezone=Asia/Shanghai
dbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/gwShopping?useSSL=true&useUnicode=true&characterEncoding=utf8
jdbc.username=root
jdbc.password=admin
二、连接数据库
测试连接成功!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)