栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Springboot整合Mybatispuls的实例详解

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Springboot整合Mybatispuls的实例详解

Springboot整合MybatisPuls

Maven导入依赖,主要只需导入MyBatisPuls


      org.springframework.boot
      spring-boot-starter-data-jdbc
    
    
      com.baomidou
      mybatis-plus-boot-starter
      3.0.1
    
    
      mysql
      mysql-connector-java
      runtime
    
    
      org.projectlombok
      lombok
      true
    

配置数据源

spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
server.port=8082

编写实体类

@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("users")//连接的表名
public class Users implements Serializable {
  @TableId("id")标记该变量为主键
  private Integer id;
  private String Account;
  @TableField("passwraod" )//如果实体类变量和数据库不同使用
  private String password;
  private Integer Authority;
}

mapper接口编写
继承baseMapper<这里为实体类>

@org.apache.ibatis.annotations.Mapper//让Spring容器扫描该类为Mapper
@Repository
public interface Mapper extends baseMapper {
}

baseMapper源码

实现接口方法

@RestController
public class Control {
  @Autowired
  Mapper mapper;
  @RequestMapping("/hello")
  public Users Select(){
    Users users = mapper.selectById(1);
    return users;
  }

}

到此这篇关于Springboot整合Mybatispuls的文章就介绍到这了,更多相关Springboot整合Mybatispuls内容请搜索考高分网以前的文章或继续浏览下面的相关文章希望大家以后多多支持考高分网!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/130499.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号