spring boot原生查询结果集psudo列未见

时间:2018-04-02 11:19:13

标签: hibernate spring-boot hibernate-native-query

考虑下面的代码,从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);
    }

@Entity

公共类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 Query result set

repo

Model

0 个答案:

没有答案