springboot + Mybatis puls 查询返回null,但是sql查询有数据

springboot + Mybatis puls 查询返回null,但是sql查询有数据

Pojo列名与数据库的不一样,或者是列名不规范!

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以按照以下步骤实现基于Spring Boot和MyBatis查询功能: 1. 首先,需要在pom.xml文件中添加Spring Boot和MyBatis的依赖项: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.0.0</version> </dependency> ``` 2. 在application.properties文件中配置MyBatis连接数据库的相关信息: ```properties spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase spring.datasource.username=root spring.datasource.password=root ``` 3. 创建一个Mapper接口,定义查询方法: ```java @Mapper public interface UserMapper { @Select("SELECT * FROM user WHERE id = #{id}") User findById(@Param("id") Long id); } ``` 4. 创建一个Service类,调用Mapper接口的查询方法: ```java @Service public class UserServiceImpl implements UserService { @Autowired private UserMapper userMapper; @Override public User findById(Long id) { return userMapper.findById(id); } } ``` 5. 在Controller中注入Service,调用查询方法: ```java @RestController public class UserController { @Autowired private UserService userService; @GetMapping("/user/{id}") public User findById(@PathVariable Long id) { return userService.findById(id); } } ``` 以上就是基于Spring Boot和MyBatis实现查询功能的代码实现过程。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值