【无标题】mybatis-plus的基本使用

1.导入依赖

<!--   导入lombok 的相关依赖     -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
<!--   导入数据源     -->  
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
<!--mybatis-plus 是自己开发的,非官方的!-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.3.1.tmp</version>
        </dependency>
1.Mapper类的书写
@Mapper // dao操作在这里开启来
public interface AccountMapper extends BaseMapper<Account> {

}
2.Service类的使用
public interface AccountService extends IService<Account> {

}
// 对应的实现类
@Service // 在这里继承 mp 提供的实现类 和 实现自己的接口类对象
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> 
implements AccountService {

}​​
3.要看见相关的sql语句的话就要配置日记
mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 在控制台上面打印
4.常用注解
@TableName("表名")
当表名与实体类名不一致时,可以在实体类上加入@TableName()声明
`@TableId`声明属性为表中的主键(若属性名称不为默认id)
`@TableFieId("字段")` 当实体类属性与表字段不一致时,可以用来声明
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "account") // 指定sql的名字
public class Account {
    @TableId(type = IdType.AUTO) 
    private Integer id;
    @TableField("cardno")
    private String cardno;
    private String password;
    private Double balance;
    private Integer status;
}
5.使用分页查询
@Configuration
public class MybatisPlusConfig {
    @Bean
    public PaginationInterceptor paginationInterceptor(){
        return new PaginationInterceptor();  
    } 
}
 

  • 7
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值