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
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 测试结果如下



