dimanche 29 décembre 2019

JPA, nativeQuery The value is shown above

The code below is repository

 @Query
                (
                        value = "select min(id) as id, coalesce (sum(case when points > 0 then points end), 0) as points, userid" +
                                " from books" +
                                " where userid = ?1" +
                                " group by userid", nativeQuery = true
                )
        JamInfo findPlus(Long userid);

    @Query
            (
                    value = "select min(id) as id, coalesce(sum(case when points < 0 then points*-1 end),0)as points, userid" +
                            " from books" +
                            " where userid = ?1" +
                            " group by userid", nativeQuery = true
            )
    JamInfo findMinus(Long userid);

The code below is controller

JamInfo jamplus = jamInfoRepository.findPlus(id);
JamInfo jamminus = jamInfoRepository.findMinus(id);
model.addAttribute("jamplus", jamplus);
model.addAttribute("jamminus", jamminus);

If you print it like this, it will be unified with the value of jamplus written first. How can the two values ​​be output differently?




Aucun commentaire:

Enregistrer un commentaire