jpa框架部分重点

1.自定义vo类接收多个实体数据时,返回数据是list集合的

1.1 service 业务层

@Override
public List> getDistrictCounty() {
    List> list = enterpriseFiscalRepository.getDistrictCounty();
    return list;
}

1.2  repository 层

@Query(value = "select \n" +
        "sum(elect.value) as electValue ,\n" +
        "sum(fiscal.output_value)  as monthValue ,\n" +
        "fiscal.year as years,\n" +
        "fiscal.months  as months ,\n" +
        "sum(fiscal.trade_income) as tradeIncome \n" +
        "from enterprise enterprise \n" +
        "left join enterprise_fiscal fiscal on fiscal.enterprise_id = enterprise.id \n" +
        "left join enterprise_elect elect on elect.enterprise_id = enterprise.id \n" +
        "group by  months , years \n" +
        "order by months , years desc",nativeQuery = true)
List> getDistrictCounty();

 2.yml配置

spring:

        jpa:
               hibernate:
                      #create 每次运行程序,没有表格会新建表格,表格内数据会清空
                      #create-drop 每次运行结束的时候回清空表
                      #update 每次运行程序,没有表格会新建表格,没有表格不会清空,只会更新
                      #validate 每次运行程序会效验数据与数据库字段类型是否相同,不同会报错
                      ddl-auto: validate

             #是否输出SQL,工作台里面是否输出
             show-sql: false
             open-in-view: false

你可能感兴趣的:(jpa)