



Spring整合MyBatis (复习)
SpringConfig
- 导入JdbcConfig
- 导入MyBatisconfig
JDBCConfig
定义数据源(加载properties配置项: driver、url、username、password )
MyBatisconfig
定义SqlsessionFactoryBean.定义映射配置


- package com.example.dao;
-
- import com.example.domain.Book;
- import org.apache.ibatis.annotations.Select;
- @Mapper
- public interface BookDao {
- @Select("Select *from tb_book where id=#{id}")
- public Book getById(Integer id);
-
- }
- package com.example.domain;
-
- public class Book {
- private Integer id;
- private String name;
- private String type;
- private String description;
-
- public Integer getId() {
- return id;
- }
-
- public void setId(Integer id) {
- this.id = id;
- }
-
- @Override
- public String toString() {
- return "Book{" +
- "id=" + id +
- ", name='" + name + '\'' +
- ", type='" + type + '\'' +
- ", description='" + description + '\'' +
- '}';
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
- }





- <!--TODO 添加必要的依赖坐标-->
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>druid</artifactId>
- <version>1.1.16</version>
- </dependency>