1、创建war项目
2、不全项目结构文件夹
3、添加maven依赖
(1)springboot父项目
<!--继承springboot父项目-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>
(2)相关启动类
<?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">
<parent>
<artifactId>springbootdemo</artifactId>
<groupId>com.offcn.springboot</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>springboot03</artifactId>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<!--web启动器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--mybatis启动器-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.2.2</version>
</dependency>
<!-- pagehelper启动器 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
<!--mysql驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
<scope>runtime</scope>
</dependency>
<!-- 阿里数据源 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!-- 热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<!-- optional=true,依赖不会往下传递,如果有项目依赖本项目,并且想要使用devtools,需要重新引入 -->
<optional>true</optional>
<scope>true</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork><!-- 如果没有该配置,热部署的devtools不生效 -->
</configuration>
</plugin>
<!-- 自定义配置spring Boot使用的JDK版本 -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
4、ssm配置
(1)库表设计
(2)实体类
(3)dao层接口
(4)mybatis映射文件
(5)mybatis配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 配置分页插件 reasonable:设置合理性分页-->
<!--合理性分页也可以在springboot的配置文件中配置-->
<!--
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<property name="reasonable" value="true"></property>
</plugin>
</plugins>
-->
</configuration>
(6)service层
(7)controller层
5、springboot配置
(1)springboot配置文件
##切换环境
spring:
profiles:
active: dev #加载application-dev.yml文件
mvc:
view:
prefix: /
suffix: .jsp
(2)application-dev.yml配置文件
##服务器配置
server:
port: 9090
servlet:
path: /sssm
##logback
logging:
config: classpath:logback.xml
##spring mvc
spring:
resources: #静态资源
static-locations:
- classpath:/META-INF/resources/
- classpath:/resources/
- classpath:/static/
- classpath:/public/
- classpath:/img/
- classpath:/js/
#创建数据源
spring:
datasource:
name: druid
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/sell
username: root
password: 123
driver-class-name: com.mysql.jdbc.Driver
#整合mybatis
mybatis:
mapper-locations: classpath:mybatis/mapper/*Mapper.xml
config-location: classpath:mybatis/mybatisConfig.xml
type-aliases-package: com.offcn.sell.dao.entity
#pagehelper
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
(3)设置主启动类
@SpringBootApplication//springboot核心注解,用于标识启动类
@ComponentScan(basePackages="com.offcn.sell")
//扫描DAO层接口
@MapperScan("com.offcn.sell.dao.mapper")
public class SellApplication
{
public static void main( String[] args )
{
//SpringApplication.run(SellerApplication.class,args);
SpringApplication application=new SpringApplication(SellApplication.class);
//关闭banner
application.setBannerMode(Banner.Mode.OFF);
application.run(args);
}
}