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中写的   括号里面是属性的名称

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章