SpringBoot 集成SSM(spring+springmvc+mabatis)

匿名 (未验证) 提交于 2019-12-03 00:21:02

SpringBoot SSMspring+springmvc+mabatis

1.

2.

window10

eclipseeclipse-jee-oxygen-3a-win32-x86_64eclipse_2018

springboottomcat

mavenspringbootmaven

3.SSM

3.1mavenweb

3.1.1.maven-web

3.1.2 GroupIDArtifactID

GroupIDJAVAmainjavacom.ypf.cn

ArtifactIDmy_springboot_ssm

3.1.3

Problems

ProblemsWindow->Show View->OtherProblems Open

Build Path

1

1

removeSource Foldersrc/main/javasrc/test/javamaven

2JDK

1.81.81.5JDK1.8

2

Edit1.8

3

3

Finish

3.2pom.xmljar

jarmaven->update Project

spring-boot-starter-aop

pring-boot-starter-web

spring-boot-starter-jdbc

spring-boot-starter-test

SpringBoot Test

mybatis-spring-boot-starter

spring bootmybatis

spring-boot-starter-logging

springbootLogback

<projectxmlns="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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.ypf.cn</groupId>

<artifactId>my_springboot_ssm</artifactId>

<packaging>war</packaging>

<version>0.0.1-SNAPSHOT</version>

<name>my_springboot_ssm MavenWebapp</name>

<url>http://maven.apache.org</url>

<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.version>1.8</java.version>

</properties>

<dependencies>

<!-- 对JDBC数据库的支持 -->

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-jdbc</artifactId>

</dependency>

<!-- mysqljdbc驱动 -->

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

<scope>runtime</scope>

</dependency>

<!-- 面向切面编程的支持,包括spring-aop和AspectJ -->

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-aop</artifactId>

</dependency>

<!-- SpringBoot Test单元测试 -->

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-test</artifactId>

<scope>test</scope>

</dependency>

<!-- spring boot整合mybatis

<dependency>

<groupId>org.mybatis.spring.boot</groupId>

<artifactId>mybatis-spring-boot-starter</artifactId>

<version>1.1.1</version>

</dependency>

<!-- springboot默认日志 Logback

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-logging</artifactId>

</dependency>

<!-- 对全栈web开发的支持,包括Tomcat和spring-webmvc

<!-- <dependency>

<!-- thymeleaf模板引擎,访问静态资源 -->

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-thymeleaf</artifactId>

</dependency>

<!-- 引入该包为了让application.properites中的 spring.thymeleaf.mode=LEGACYHTML5 生效,

是为了解决 thymeleaf模板引擎过于严格的HTML校验-->

<dependency>

<groupId>net.sourceforge.nekohtml</groupId>

<artifactId>nekohtml</artifactId>

</dependency>

</dependencies>

<build>

<plugins>

<!-- SpringBoot的maven插件 -->

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

</plugin>

</plugins>

</build>

</project>

3.3

mytestuser

sql

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------

-- Table structure for `user`

-- ----------------------------

DROP TABLE IF EXISTS `user`;

CREATE TABLE `user` (

) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

-- ----------------------------

-- Records of user

-- ----------------------------

INSERT INTO `user` VALUES ('1', '', '16');

INSERT INTO `user` VALUES ('2', '', '24');

3.4JSON

3.4.1 application.properties

SpringBootapplication.propertiesapplication.ymlapplication.propertiesapplication.yml

application.properties

server.port=9996

server.tomcat.uri-encoding=utf-8

#MySQL

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.datasource.url=jdbc:mysql://localhost:3306/mytest?characterEncoding=utf8

spring.datasource.username=root

spring.datasource.password=root

spring.jpa.database=mysql

#Mybatis

mybatis.mapper-locations=classpath*:mapper/*Mapper.xml

logging.level.org.springframework=WARN

logging.level.com.yfp.cn=DEBUG

logging.file=logs/spring-boot-logging.log

#remove thymeleaf

spring.thymeleaf.mode=LEGACYHTML5

spring.thymeleaf.cache=false

spring.thymeleaf.prefix=/WEB-INF/

spring.thymeleaf.suffix=.html

#spring.thymeleaf.content-type=text/html

# don't use it because it's inoperative

#spring.mvc.view.prefix=/views/

#spring.mvc.view.suffix=.html

#spring.mvc.view.prefix=/WEB-INF/views/

#spring.mvc.view.suffix=.jsp

application.yml

3.4.2 MySpringBootApplication

SpringBoot

MySpringBootApplication.java

package

import

importorg.springframework.boot.autoconfigure.SpringBootApplication;

import

@SpringBootApplication

@EnableTransactionManagement//开启事务管理

publicclass

publicstaticvoidargs) {

run(MySpringBootApplication.class, args);

}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!