SpringBoot整合ssm

创建项目的时候要注意,勾选架包是spring web,jdbc api,mysql driver,mybatis framework

不要随意的钩选其他的架包,不然会报错

xx

controller,services,model,mapper中的写法和以前一样,是不需要以前的mybatis,springmvc,spring的一些配置文件的

然后写完后,在application的类的上方加@MapperScaan扫描mapperxie

package com.ywy;

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

//配置mapper扫描
@MapperScan(basePackages = "com.ywy.mapper")
@SpringBootApplication
public class Springboot02Application {

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

}

写完后在application.properties的配置文件

server.port=80
server.servlet.context-path=/ssm

##?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false
##配置数据源
##数据库后面加的?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false是因为数据库依赖是最高版本的,我的数据库是以前的版本,然后就需要加
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

##如果用注解的方式,不用写别名和映射文件
##配置别名
mybatis.type-aliases-package=com.ywy.model
##配置实体类的映射文件
mybatis.mapper-locations=classpath:com/ywy/model/*.xml

 

注:@AutoWired  将属性依赖注入到

private UserMapper usermapper;

@Service("usermapper") impl中写的   括号里面是属性的名称

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值