@SpringBootTest
public class BookJdbcTest {
@Autowired
private JdbcTemplate jdbcTemplate;
@Test
public void testBookSave(){
String sql = "insert into TBL_BOOK (id, type, name, description) values (2, 'springboot2', 'springboot2', 'springboot2')";
jdbcTemplate.update(sql);
}
@Test
public void testSelect(){
String sql= "select * from tbl_book";
List<Book> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Book.class));
query.forEach(System.out::println);
}
}
操作数据库代码2:mybatis-plus
java复制代码
@SpringBootTest
public class BookMybatisPlusTest {
@Autowired
private IBookService bookService;
@Test
public void testSave(){
Book book = new Book();
book.setId(3);
book.setName("springboot3");
book.setType("springboot3");
book.setDescription("springboot3");
bookService.save(book);
}
@Test
public void testSelect(){
Book book = bookService.getById(3);
System.out.println(book);
}
}