ssm -tk-mybatis

tk-mybatis :单表操作是无敌的
一)引入依赖

tk.mybatis
mapper-spring-boot-starter
2.1.5

二)配置appliction.yml
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql:///testdb?useSSL=true
username: root
password:123456
mapper:
identity: MYSQL
not-empty: true
mappers:
- tk.mybatis.mapper.common.Mapper
- tk.mybatis.mapper.common.MySqlMapper
#启用日志打印SQL语句 level是mapper的包路径
logging:
level:
com.example.bootssm2.mapper: debug

三)
/**

  • 项目中所有mapper类的父类
  • @param
    */
    public interface BaseMapper extends Mapper , MySqlMapper {
    }

四)
由于项目mapper文件很都,可以在启动类中用
@MapperScan(“可以多个包路径,用逗号隔开”)
注意用tk-mybatis中的@MapperScan
public interface BookInfoMapper extends BaseMapper {

}
五)
@SpringBootApplication
@MapperScan(“com.example.bootssm2.mapper”)
public class BootSsm2Application {

public static void main(String[] args) {

    ConfigurableApplicationContext
            context = SpringApplication.run(BootSsm2Application.class, args);
    BookInfoMapper mapper = context.getBean(BookInfoMapper.class);
    BookInfo book1 = mapper.selectByPrimaryKey("5");
    mapper.insertList(Arrays.asList(book1));

}

}
六)
@Data
@AllArgsConstructor
@NoArgsConstructor
@Table(name = “t_book”) //映射表
public class BookInfo {
@Id //定义主键
private Integer bookId;
private String bookName;
private String bookAuthor;
private BigDecimal bookPrice;
}

//坑:注意要定义主键

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值