Springboot整合Mybatispuls的实例详解

网友投稿 667 2023-03-14

Springboot整合Mybatispuls的实例详解

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 idNsTsl;

private String Account;

@TableField("passwraod" )//如果实体类变量和数据库不同使用

private String password;

private Integer Authttp://hority;

}

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;

}

}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:超级APP(超级电销app)
下一篇:苹果电脑不能打开小程序(苹果电脑可以打开小程序吗)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~