美文网首页
springboot搭建ssm

springboot搭建ssm

作者: 笨笨翔 | 来源:发表于2018-08-15 17:57 被阅读0次

1.第一步创建SpringBootApplication

1.1 File->new->Project


image.png

1.2 这里配置项目名,包名以及maven的版本等配置


image.png
1.3 在这里勾选web,mybatis待会手动添加
image.png

1.4 项目名和地址,一个新的springboot项目就新鲜出炉了。


image.png
1.5 这是项目的结构,我把application.properties,改为了application.yml
image.png
  1. 添加maven依赖
<?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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example.ssm</groupId>
    <artifactId>ssm</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>test</name>
    <description>Demo project for Spring Boot</description>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.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>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- 新项目添加的所有依赖 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.1.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

  1. 配置application.yml
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/xiaodong
    username: root
    password: ******
    driver-class-name: com.mysql.jdbc.Driver
  jpa:
    database: mysql
mybatis:
  #mysql扫描包
  mapper-locations: classpath*:mapper/*.xml
  #起别名。可省略写mybatis的xml中的resultType的全路径
  type-aliases-package: com.example.ssm.test.entity
  1. 在启动类加上@MapperScan(basePackages ={"com.example.ssm.test.dao"})注解,还有开启事物注解@EnableTransactionManagement
    一个最简单的springboot的ssm项目就搭建完成了。

相关文章

网友评论

      本文标题:springboot搭建ssm

      本文链接:https://www.haomeiwen.com/subject/ysuwbftx.html