【springboot 配置ssm】

这里使用idea maven 自动配置

一.导入必要的jar仓库

导入jar

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <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-starter-jdbc</artifactId>
        </dependency>

        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.1</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>.导入配置(idea 默认不编译java 包下的 xml,如 mapper .xml)
 <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>

        </resources>

三.整合mybaits .

在这里插入图片描述
在配置文件application.yml 下

#\u516C\u5171\u914D\u7F6E
server:
  port: 8080
  tomcat:
    uri-encoding: UTF-8 #tmcat 配置
spring:
  #\u89C6\u56FE\u914D\u7F6E
  mvc:
    static-path-pattern: /**
  resources:
    static-locations: classpath:/ #死都要加上classpath
   
  thymeleaf:
    prefix: classpath:/templates/ #thymeleaf 模板配置
    suffix: .html
    mode: HTML
    encoding: UTF-8
    cache: false

  datasource:
    url: jdbc:mysql://localhost:3306/cat-cloud?useUnicode=true&characterEncoding=utf-8  #数据源
    username: root
    password: 123456
    driver-class-name: com.mysql.jdbc.Driver

mybatis:
  mapper-locations: classpath:mapper/*Mapper.xml #指定mapper 路径
  type-aliases-package: com.unlzh.catcloud.pojo #别名配置

四.文件格式
在这里插入图片描述
静态文件默认放在,resources/static 文件夹下
网页文件默认放在,resouces/templates文件夹下

五.注意点

1.mapper 接口必须加入
@mapper ,否则spring 找不到接口 完成不了映射

2.如果没有加入@mapper 注解,需要在启动类中接入@mapperScanner 注解

六.测试
Controller
在这里插入图片描述
在这里插入图片描述
启动类

package com.unlzh.catcloud;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@MapperScan("com.unlzh.catcloud.mapper")
public class CatCloudApplication {

    public static void main(String[] args) {
        SpringApplication.run(CatCloudApplication.class, args);
    }

}

启动后

```![在这里插入图片描述](https://img-blog.csdnimg.cn/20191012205146577.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L21hMTIxMzg=,size_16,color_FFFFFF,t_70)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值