IDEA
MySQL 5.7.19
Tomcat 9
Maven 3.6
(1)数据库环境
创建一个存放书籍数据的数据库表,需要注意是一个行模块进行执行,不要全部一起,会报错
- CREATE DATABASE `ssmbuild`;
-
- USE `ssmbuild`;
-
- DROP TABLE IF EXISTS `books`;
-
- CREATE TABLE `books` (
- `bookID` INT(10) NOT NULL AUTO_INCREMENT COMMENT '书id',
- `bookName` VARCHAR(100) NOT NULL COMMENT '书名',
- `bookCounts` INT(11) NOT NULL COMMENT '数量',
- `detail` VARCHAR(200) NOT NULL COMMENT '描述',
- KEY `bookID` (`bookID`)
- ) ENGINE=INNODB DEFAULT CHARSET=utf8
-
- INSERT INTO `books`(`bookID`,`bookName`,`bookCounts`,`detail`)VALUES
- (1,'Java',1,'从入门到放弃'),
- (2,'MySQL',10,'从删库到跑路'),
- (3,'Linux',5,'从进门到进牢');
(2)新建一Maven项目!ssmbuild
(3)导入相关的pom依赖
-
- <dependencies>
-
- <dependency>
- <groupId>junitgroupId>
- <artifactId>junitartifactId>
- <version>4.12version>
- dependency>
-
- <dependency>
- <groupId>mysqlgroupId>
- <artifactId>mysql-connector-javaartifactId>
- <version>5.1.47version>
- dependency>
-
- <dependency>
- <groupId>com.mchangegroupId>
- <artifactId>c3p0artifactId>
- <version>0.9.5.5version>
- dependency>
-
-
- <dependency>
- <groupId>javax.servletgroupId>
- <artifactId>servlet-apiartifactId>
- <version>2.5version>
- dependency>
- <dependency>
- <groupId>javax.servlet.jspgroupId>
- <artifactId>jsp-apiartifactId>
- <version>2.2version>
- dependency>
- <dependency>
- <groupId>javax.servletgroupId>
- <artifactId>jstlartifactId>
- <version>1.2version>
- dependency>
-
-
- <dependency>
- <groupId>org.mybatisgroupId>
- <artifactId>mybatisartifactId>
- <version>3.5.9version>
- dependency>
- <dependency>
- <groupId>org.mybatisgroupId>
- <artifactId>mybatis-springartifactId>
- <version>2.0.6version>
- dependency>
-
-
- <dependency>
- <groupId>org.springframeworkgroupId>
- <artifactId>spring-webmvcartifactId>
- <version>5.3.19version>
- dependency>
- <dependency>
- <groupId>org.springframeworkgroupId>
- <artifactId>spring-jdbcartifactId>
- <version>5.3.19version>
- dependency>
- <dependency>
- <groupId>org.projectlombokgroupId>
- <artifactId>lombokartifactId>
- <version>1.18.24version>
- dependency>
- dependencies>
(4)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>
(5)连接数据库
设置时间区域(版本过低的需要!)
输入账户密码,测试是否成功!
选择创建的数据库(ssmbuild)
(6)建立基本结构和配置框架
com.gt.pojo
com.gt.mapper
com.gt.service
com.gt.controller
- "1.0" encoding="UTF-8" ?>
- configuration
- PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-config.dtd">
- <configuration>
-
- configuration>
- "1.0" encoding="UTF-8"?>
- <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&