【发布时间】:2020-04-17 14:01:11
【问题描述】:
我在 java restful API 中使用带有安全性的 spring boot。我希望根据我的要求做出适当的回应。我将向您展示我的数据库表并要求响应。我还将向您展示我尝试过的代码。 我已经尝试过,但响应没有按照我的要求得到适当的。有人知道吗?该怎么做?
"eventColorLegends": [
{
"color": "Red",
"items": [
"Musician1",
"Workshop",
"Seminart"
]
},
{
"color": "Black",
"items": [
"Product Launches",
"Incentive Trips"
]
},
{
"color": "Green",
"items": [
"Dancing",
"Rotary - Service Club",
"Historical/Remembrance"
]
},
{
"color": "Yellow",
"items": [
"Party",
"Incubator - Accelerator",
"Leads - Referral"
]
},
{
"color": "Orange",
"items": [
"Charity",
"Non-profit",
"Rotary - Service Club",
"Historical/Remembrance",
]
},
{
"color": "Coffee",
"items": [
"Incubator - Accelerator"
]
},
{
"color": "Blue",
"items": [
"Leads - Referral",
"Historical/Remembrance",
"Rotary - Service Club",
"For-Profit Company",
]
},
]
- 我尝试了 serviceImpl 类中的代码
public GenericResponse findAllTypeOfEvents() {
try {
List<TypesOfEvents> typesOfEventsList = typeOfEventsDao.findAll();
List<String> listEvents = new ArrayList<String>();
for (int i = 0; i < typesOfEventsList.size(); i++) {
for (int j = i + 1; j < typesOfEventsList.size()- 1; j++) {
if (typesOfEventsList.get(i).getColor().equalsIgnoreCase(typesOfEventsList.get(j).getColor())) {
if (typesOfEventsList.get(j).getType().equalsIgnoreCase(typesOfEventsList.get(j).getType())){
listEvents.add(i,typesOfEventsList.get(j).getType());
System.out.println(typesOfEventsList.get(i).getColor() + " : " + typesOfEventsList.get(j).getType());
}
}
}
}
return APIResponseBuilder.build(true, listEvents.toArray(), typesOfEventsList.size() > 0 ? commonMessages.findAllTrue : commonMessages.findAllFalse);
} catch (Exception e) {
logger.error(commonMessages.findAllException + "TypesOfEvents " + e.getMessage());
return APIResponseBuilder.build(false, e.getMessage(), commonMessages.exception);
}
}
4.我的回应
"data": [
"Seminart",
"For-Profit Company",
"For-Profit Company",
"Historical/Remembrance",
"Leads - Referral",
"Historical/Remembrance",
"Historical/Remembrance",
"Historical/Remembrance",
"Rotary - Service Club",
"For-Profit Company",
"For-Profit Company",
"For-Profit Company",
"Historical/Remembrance",
"Seminart",
"Seminart",
"Historical/Remembrance",
"Workshop",
"Leads - Referral",
"Leads - Referral",
"For-Profit Company",
"Incubator - Accelerator",
"Seminart",
"Historical/Remembrance",
"Leads - Referral",
"Leads - Referral",
"Leads - Referral",
"Incubator - Accelerator",
"For-Profit Company",
"Incubator - Accelerator",
"Historical/Remembrance",
"Rotary - Service Club",
"Incubator - Accelerator",
"Historical/Remembrance",
"Rotary - Service Club",
"Leads - Referral",
"Workshop",
"Seminart",
"Historical/Remembrance",
"Rotary - Service Club",
"Non-profit",
"Incubator - Accelerator",
"Historical/Remembrance",
"Rotary - Service Club",
"Leads - Referral",
"Incubator - Accelerator",
"Rotary - Service Club",
"Historical/Remembrance",
"Historical/Remembrance",
"Incentive Trips",
"Workshop",
"Seminart",
"Workshop"
]
}
【问题讨论】:
-
那很好,但是你为什么不把你的数据发布为文本或 dbfiddle,当你在它的时候。
-
我已经添加了我的回复
标签: java mysql spring-boot spring-data-jpa spring-boot-actuator