Jpa @Query nativeQuery=true

"message""No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] to type [com.cocabit.jwtdemo.vo.StudentVo]",

@Entity
@Data
public class Student {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	private String name;
	private String address;
}


@Data
public class StudentVo {
	private String name;
}
  • Student对应数据库
  • StudentVo展示用

通过在Repository中使用@Query的nativeQuery查询

public interface StudentRepostory extends JpaRepository<Student, Long> {
	@Query(nativeQuery = true,value="select name as name from student")
	List<StudentVo> findName();
}

调试一下

发生了什么。

用Student试了下,是OK的。

解决方案,

public interface StudentVo {
	String getName();
}