Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自定义查询接口使用 select * 查询无法自动处理 @Column 定义的字段 #657

Closed
zlx opened this issue Sep 9, 2019 · 2 comments

Comments

@zlx
Copy link

zlx commented Sep 9, 2019

当我使用自定义的查询 ArticleMapper#findByName 查出数据发现 abstractInfo 这个属性信息为 null。

重现步骤:

有以下 po 和 dao:

po/Article.java

@Data
@Accessors(chain = true)
@Table(name = "articles")
public class Article {

  @Id
  private Long id;
  private String name;
  private String body;
  @Column(name = "abstract")
  private String abstractInfo;
...

dao/ArticleMapper.java

public interface ArticleMapper extends Mapper<Article> {
    
    @Select("select * from articles where name = #{name}")
    Collection<Article> findByName(String name);
   ...

但是使用 selectByExample 方法查询数据是可以正常获取 abstractInfo 这个属性值,对比发现其查询语句为 select id,name,body,abstract from articles where name = ?

请问一下有办法可以不自己指定全部字段也能实现自动封装 @Column 注解的属性值吗?

测试环境版本:

<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>2.1.4.RELEASE</version>
	<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
	<groupId>org.mybatis.spring.boot</groupId>
	<artifactId>mybatis-spring-boot-starter</artifactId>
	<version>2.0.1</version>
</dependency>
<dependency>
	<groupId>tk.mybatis</groupId>
	<artifactId>mapper-spring-boot-starter</artifactId>
	<version>2.1.5</version>
</dependency>
<dependency>
	<groupId>tk.mybatis</groupId>
	<artifactId>mapper-core</artifactId>
	<version>RELEASE</version>
</dependency>
@qrqhuang
Copy link
Contributor

应该是不能实现。
@select 式写法, 为mybatis 原生方式, 其不支持@column注解。

Mapper中, 有对 如上注解特殊处理。
可以看下:

@zlx
Copy link
Author

zlx commented Sep 30, 2019

谢谢,了解 Mybatis 并没有实现 JPA,@column 都是自己支持的是吧。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants