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

maven的springboot整合mybatis

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

maven的springboot整合mybatis

1.先看项目机构图

2.依赖

    
    
        org.springframework.boot
        spring-boot-starter-parent
        2.7.0
        
    
    
        1.8
    

    
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            org.springframework.boot
            spring-boot-starter-jdbc
            2.7.0
        
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            2.2.2
        
        
        
            org.mybatis
            mybatis
            3.5.9
        
        
            mysql
            mysql-connector-java
            5.1.44
        
        
            com.alibaba
            druid
            1.1.16
        
        
        
            org.projectlombok
            lombok
        
    

 2.配置文件application.yml

server:
  port: 8080
spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/test
    username: root
    password: 123456
mybatis:
  mapper-locations: classpath:com.ty.mapper/*.xml
  type-aliases-package: com.ty.bean
logging:
  level:
    com.ty.mapper: debug

3.创建启动类程序入口

package com.ty;

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


@MapperScan("com.ty.mapper")
@SpringBootApplication
public class Application {
    public static void main(String[] args){
        SpringApplication.run(Application.class,args);
    }
}

4.写三层架构、bean、controller、mapper、service……

5.写映射文件mapper.xml




    
        select * from user where username = #{username} and password = #{password}
    

6.数据库表的创建

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/952791.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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