我试图将查询限制为仅从要使用的表中选择特定列,但是当我编写一个简单的选择查询时,我最终遇到了错误
已解决[org.springframework.core.convert.ConversionFailedException:无法从类型[java.lang.Object[]]转换为类型[@org.springframework.data.jpa.repository.Query com.aims.covidsurvey.models.Users ] 对于值“{44,test@gmail.com,约翰,史密斯}”;嵌套异常是 org.springframework.core.convert
当我选择全部时,没有错误,但它选择了一些大列,这些列需要很长时间才能执行查询。
这就是我到目前为止所做的
我的存储库
public interface ProductRepository extends JpaRepository<Users, Long> {
@Query("SELECT p FROM Users p WHERE CONCAT(p.id, ' ', p.email, ' ', p.firstname, ' ', p.surname) LIKE %?1%")
List<Users> search(String keyword);
@Query("SELECT e.id, e.email, e.firstname, e.surname FROM Users e")
List<Users> findByQuery();
}
Run Code Online (Sandbox Code Playgroud)
我的服务
@Service
public class ProductService {
@Autowired
private ProductRepository repo;
public List<Users> listAll(String keyword) {
if (keyword != null) {
return repo.search(keyword);
}
return repo.findByQuery();
}
}
Run Code Online (Sandbox Code Playgroud)
我的模特班
@Entity
@Table(name = "users") …Run Code Online (Sandbox Code Playgroud)