栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springboot整合mybatis

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springboot整合mybatis

基于搭建好的springcloud项目

https://blog.csdn.net/jdbcmeng/article/details/125423022

maven依赖
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            2.1.3
        
        
            mysql
            mysql-connector-java
            5.1.6
        
        
            com.alibaba
            druid
            1.1.20
        
application.yml
# Database base configuration
spring:
  datasource:
      driverClassName: com.mysql.jdbc.Driver
      url: jdbc:mysql://192.168.233.129:3306/mydata?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
      username: root
      password: 123456
mybatis:
    mapperLocations: classpath*:mapper/*Mapper.xml

# 打印sql语句
logging:
    level:
        com.meng.user: debug

扫描Dao
@SpringBootApplication
@MapperScan(value = "com.meng")
public class MyApplication {
    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class , args);
    }
}
打印日志
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("/findAll")
    public List findAll(){
        log.info("finall bei diao yong le -----------");
        return userService.findAll();
    }

    @GetMapping("/find/{id}")
    public User find(@PathVariable(value = "id")Integer id){
        log.info("find bei diao yong le ----------params-{}" , id);
        return userService.findById(id);
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/988761.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号