【发布时间】:2018-12-03 09:49:25
【问题描述】:
我从数据库中得到一个包含每月数据的列表。目前我已经根据数据库将数据从January 排序到December。
但我希望输出应该从June开始,结束月份应该是May。
示例输出列表:
[
{
"accountlinevaluesId": 8,
"accountlineId": 3,
"month": "januar",
"accountNumber": 177,
"name": "Befestigungen",
"amount": 0
},
{
"accountlinevaluesId": 9,
"accountlineId": 3,
"month": "januar",
"accountNumber": 179,
"name": "Andere Bauten",
"amount": -625
}, {
"accountlinevaluesId": 165,
"accountlineId": 4,
"month": "februar",
"accountNumber": 179,
"name": "Andere Bauten",
"amount": -625
},
{
"accountlinevaluesId": 166,
"accountlineId": 4,
"month": "februar",
"accountNumber": 210,
"name": "Maschinen",
"amount": -1962
}, {
"accountlinevaluesId": 329,
"accountlineId": 5,
"month": "maerz",
"accountNumber": 211,
"name": "Testgestell",
"amount": -897.75
},
{
"accountlinevaluesId": 330,
"accountlineId": 5,
"month": "maerz",
"accountNumber": 233,
"name": "Motor f. Arbeitsplattfo",
"amount": 0
}]
谁能告诉我如何才能最好地进行以及如何在 Java 中解决这个问题?
当前查询如下所示:
public List<AccountlinevaluesEntity> findAllAccountLineValuesByMandantId(Long mandantId, String title, String context, String month) {
List<AccountlinevaluesEntity> accountLineValues = new ArrayList();
if (mandantId > 0 && title != null && context !=null) {
try {
List accountIds = new AccountManager().findAccountByMandantId(mandantId);
startOperation(false);
if (accountIds != null && accountIds.size() > 0) {
List accountLineIds =
getSession()
.createQuery("SELECT ale.accountlineId FROM AccountlineEntity ale WHERE ale.accountId IN :accountIds AND ale.title = :title AND ale.context = :context")
.setParameter("accountIds", accountIds)
.setParameter("title", title)
.setParameter("context", context)
.list();
if (accountLineIds != null && accountLineIds.size() > 0) {
if (month == null) {
return getSession()
.createQuery("SELECT alve FROM AccountlinevaluesEntity alve WHERE alve.accountlineId IN :accountlineIds")
.setParameter("accountlineIds", accountLineIds)
.list();
} else {
return getSession()
.createQuery("SELECT alve FROM AccountlinevaluesEntity alve WHERE alve.accountlineId IN :accountlineIds AND alve.month = :month")
.setParameter("accountlineIds", accountLineIds)
.setParameter("month", month)
.list();
}
}
}
} catch (HibernateException e) {
handleException(e);
} finally {
getSession().close();
}
}
return accountLineValues;
}
【问题讨论】:
-
是否可以更改数据库查询或者这不是一个选项?
-
到目前为止你尝试过什么?了解比较器
-
不幸的是,我不需要前端中的列表完全相同,但也如上所述。不想使用第二个查询
-
我们甚至不知道您如何获取这些数据,或者您如何打印它。所以,请阅读minimal reproducible example 并向我们展示您解决此问题的尝试,并指出您遇到的具体问题。
-
如果逻辑说一年开始,例如,六月,我想操纵列表,以便输出从六月开始到五月,而不是从一月到十二月。我想用Java解决这个问题。数据作为 Json 发送到前端。我们使用 Angular 作为我们的前端。但我只做后端部分