随着spring4.0的版本发布,springboot一个非常好的框架简化了后端人员的开发布局。那么在此,这里是基于maven与springboot整合的一个ssm框架。springboot-spring-springmvc-mybatis快速框架。
如果觉得文章不错,对你有帮助,请作者喝杯咖啡,谢谢!如果对您有帮助 ,请多多支持.多少都是您的心意与支持,一分也是爱,再次感谢!!!打开支付宝首页搜“556723462”领红包,领到大红包的小伙伴赶紧使用哦!感谢大家的支持!您的支持,我会继续分享更多的文章,欢迎关注!
微信端 | 支付宝端 | 支付宝红包端 |
1,创建一个maven项目如下图所示:
2,在pom.xml导入springboot-ssm所需要的jar包版本依赖,具体依赖如下:
<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>com.springboot.ssm1</groupId>
<artifactId>springboot-ssm1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<description>这是一个基于springboot整合的一个ssm项目</description>
<!--springboot你目录配置依赖的版本 ,必要添加 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<!--指定编码 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- java编译插件,设置jdk的版本 -->
<java.version>1.8</java.version>
</properties>
<dependencies>
<!--springbobot-mybatis依赖版本 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- mysql依赖 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- 这是oracle依赖,因这里使用的是Mysql数据库,因此这里注释掉了 -->
<!-- <dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency> -->
<!--spring-tomcat 依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- springboot-test依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 开发工具,包含热部署等功能,热部署,修改代码的时候不需要重启项目,会自动更新项目 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!-- swagger Swagger介绍 Swagger是当前最好用的Restful API文档生成的开源项目,通过swagger-spring项目
实现了与SpingMVC框架的无缝集成功能,方便生成spring restful风格的接口文档, 同时swagger-ui还可以测试spring
restful风格的接口功能。 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
</dependencies>
<build>
<!-- maven启动方式的插件 -->
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
3.配置application.properties具体如下:
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/ssm?useUnicode=true&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=123456
#tomcat端口配置,这里是8080
server.port=8080
那么到此,springboot整合ssm就好了!!!!,是不是很easy,很惊讶!这才是刚开始,路漫漫其修远兮,吾将上下而求索。
4.测试,springboot的一个主入口,具体代码如下:
package com.spring.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller//标明这是一个SpringMVC的Controller控制器;
@SpringBootApplication//Spring Boot项目的核心注解,主要目的是开启自动配置。
//SpringBootApplication:包含@Configuration、@EnableAutoConfiguration、@ComponentScan
public class HelloApplication {
@RequestMapping("hello")//请求路径
@ResponseBody//返回json数据
public String hello() {
return "hello world! 你好世界!";
}
//在main方法中启动一个应用,即:这个应用的入口
public static void main(String[] args) {
//springboot的启动入口
SpringApplication.run(HelloApplication.class, args);
}
}
在浏览器中输入请求地址如图所示: