2 回答
TA贡献1880条经验 获得超4个赞
I suppose you are getting error at this line:
List<Product> productList = session.createQuery(" select productName, count(productName) as totalSold from Product where sell='1' group by productName Order by totalSold desc").setCacheable(true).list();
You need to write DTO for this.
class ProductDto {
private ProductName;
int productCount;
//getters and setters and constructors
}
you can accordingly modify the query as:
List<ProductDto> productDtoList = session.createQuery(" select new ProductDto (productName, count(productName)) from Product where sell='1' group by productName order by count(productName) desc").setCacheable(true).list();
TA贡献1893条经验 获得超10个赞
我不明白如何将查询的结果转换为 Product 实例,特别是在选择中包含 count() 。
我会更改查询的以下部分
select productName, count(productName) as totalSold from Product
对此
SELECT * FROM Product
(也许用实际的列名替换 * )
添加回答
举报