考虑下面的代码,该代码从 mysqlDB 中提取名为“ice”的表。问题是我可以看到 IceCreamModel{id=101, description='vanilla', price=10, mulfactor=2} 。但在执行代码时无法查看“总计”psudo 列。
public interface IceCreamRepository extends jpaRepository<IceCreamModel,Integer> {
@Query(value = "SELECT id, description,price, mulfactor, price * mulfactor as 'total' FROM ice WHERE id=101",nativeQuery = true)
List<IceCreamModel> getMul();
}
@Autowired
private IceCreamRepository iceCreamRepository;
public static void main(String[] args) {
SpringApplication.run(DesignPatternsApplication.class, args);
@Override
public void run(String... args) throws Exception {
getMul();
}
private void getMul() {
List<IceCreamModel> list=iceCreamRepository.getMul();
list.forEach(System.out::println);
}
@实体
公共类 IceCreamModel 实现 Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private int id;
private String description;
private int price;
private int mulfactor;
}
// Mysql查询结果集