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

SpringBoot+Mybatis+Sybase整合

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

SpringBoot+Mybatis+Sybase整合

1.1 创建SpringBoot项目



1.2 添加pom依赖和导入jar包


    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.5.0
         
    
    com.itheima
    springboot_05_mybatis
    0.0.1-SNAPSHOT
    springboot_05_mybatis
    Demo project for Spring Boot
    
        1.8
    
    
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            2.2.0
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
                2.5.0
            
            
            
                org.apache.maven.plugins
                maven-surefire-plugin
                2.22.2
                
                    true
                
            
        
    



导入sybase driver jar包

下载地址: https://download.csdn.net/download/qq_22075913/85047736

1.3 添加application.yml配置文件


1.4 准备表数据
create table tbl_book(
bid int NOT NULL,
btype varchar(20) NULL,
name varchar(50) NULL,
description varchar(255) NULL
)
CREATE UNIQUE INDEX tbl_book_idx1 ON db_vas.dbo.tbl_book (bid)


insert into tbl_book values(1,'计算机理论','spring实战第五版','Spring入门经典教程')
insert into tbl_book values(2,'计算机理论','Java编程思想','Java学习必读经典')
insert into tbl_book values(3,'计算机理论','深入理解java虚拟机','5个维度全面剖析JVM')
insert into tbl_book values(4,'计算机理论','Spring 5设计模式','深入spring源码剖析Spring源码中蕴含的10大设计模式')
insert into tbl_book values(5,'计算机理论','spring实战第五版','Spring入门经典教程')
1.5 Book实体类
package com.itheima.entity;

public class Book {
    private Integer bid;
    private String btype;
    private String name;
    private String description;

    public Integer getBid() {
        return bid;
    }

    public void setBid(Integer bid) {
        this.bid = bid;
    }

    public String getBtype() {
        return btype;
    }

    public void setBtype(String btype) {
        this.btype = btype;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public String toString() {
        return "Book{" +
                "bid=" + bid +
                ", btype='" + btype + ''' +
                ", name='" + name + ''' +
                ", description='" + description + ''' +
                '}';
    }
}

1.6 BookDao
package com.itheima.dao;

import com.itheima.entity.Book;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface BookDao {
    @Select("select *from tbl_book where bid=#{id}")
    public Book getById(Integer bid);
}

1.7 编写测试类
package com.itheima;
import com.itheima.dao.BookDao;
import com.itheima.entity.Book;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class Springboot05MybatisApplicationTests {
    @Autowired
    private BookDao bookDao;


    @Test
    void contextLoads() {
        Book book = bookDao.getById(1);
        System.out.println(book);
    }
}

1.8 测试结果如下

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

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

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