Home > Back-end >  Spring Boot parameters of the Controller performance
Spring Boot parameters of the Controller performance

Time:11-25

Do the back-end recently in use with Spring Boot, struggle a question
Map And custom dtos performance gap
1. Use Map Is very convenient, and don't have to define a lot of classes, but because the Object will involve a lot of packing and unpacking, will cause the loss of performance,
2. Define multiple input and output of dto classes, looks clear, but very troublesome,

But I wrote 2 this kind of method, and then tested, found that performance is not much difference, have who can explain to me?
Labeled as part of the code below, if have bad place, please point out,

This is to use Map
 @ PostMapping (path="/gettimebymember") 
Public Map GetTimeByAdAccountAndMember (@ RequestBody Map Obj) {
Map Ret=new HashMap (a);
Map Data=https://bbs.csdn.net/topics/new HashMap ();

Try {
//find out the account all subordinates
String date=(String) obj. Get (" date ");
String adAccount=(String) obj. Get (" adAccount ");
The UserInfo supervisor=userInfoService. GetUserInfoByAdAccount (adAccount);
Int yearInt=Integer. ParseInt (date. The substring (0, date. IndexOf (' - ')));
List List=userInfoService. ListAllActive ();
List Members=new ArrayList (a);
Members. The add (supervisor);
For (the UserInfo user: list)
{
String name1=user. GetSupervisor ();
String name2=adAccount;
If (name1==null)
continue;

If (name1. Equals (name2))
{
Members. The add (user);
}
}

If (members. IsEmpty ())
{
Ret. Put (" data ", "0");
return ret;
}

//to find every subordinate this year monthly time
String [] monthName={" Jan ", "Feb.", "Mar.," "Apr.," "May,", "Jun.", "Jul.," ". ", "Sep.", "Oct., Nov., Dec." "};
For (the UserInfo m: members)
{
Double [] memberTime=new double [12].
Map Member=new HashMap (a);
String AD=m.g etAdAccount ();
for(int i=1; I & lt;=12; I++)
{
The Date firstDate=Helper. GetFirstDayOfMonth (yearInt, I);
The Date lastDate=Helper. GetLastDayOfMonth (yearInt, I);
The Date firstMondy=Helper. GetMondyDayOfDate (firstDate);
The Date lastMondy=Helper. GetMondyDayOfDate (lastDate);

List WBSList=taskService. GetWBSList (AD);

The Date startDate=firstMondy;
Double monthtime=0;
While (startDate. GetTime () & lt; .=lastMondy getTime ())
{
Double the daytime=0;
For (String WBS: WBSList)
{
List Cats=taskCatsService. GetTimeForSpecialWBS (AD, WBS, startDate, I);
Double wbstime=0;
For (the Map item: cats)
{
Wbstime +=(double) item. Get (" workingHours ");
}
The daytime +=wbstime;
}
Monthtime +=the daytime;
StartDate=Helper. PlusDate (7, startDate);
}
Member. The put (monthName] [I - 1, monthtime);
MemberTime] [I - 1=monthtime;
}
Data. The put (AD, memberTime);
}
Ret. Put (" Data ", Data);
return ret;
} the catch (Exception ex)
{
Ret. Put (" data ", "0");
return ret;
}
}


This is a custom class
 @ PostMapping (path="/gettimebymembermirror") 
Public Map GetTimeByAdAccountAndMemberMirror (@ RequestBody InputDto InputDto) {
Map Ret=new HashMap (a);
List Data=https://bbs.csdn.net/topics/new ArrayList ();
Try {
//find out the account all subordinates
String date=inputDto. GetDate ();
String adAccount=inputDto. GetAdAccount ();
The UserInfo supervisor=userInfoService. GetUserInfoByAdAccount (adAccount);
Int yearInt=Integer. ParseInt (date. The substring (0, date. IndexOf (' - ')));
List List=userInfoService. ListAllActive ();
List Members=new ArrayList (a);
Members. The add (supervisor);
For (the UserInfo user: list)
{
String name1=user. GetSupervisor ();
String name2=adAccount;
If (name1==null)
continue;

If (name1. Equals (name2))
{
Members. The add (user);
}
}

If (members. IsEmpty ())
{
Ret. Put (" data ", "0");
return ret;
}

//to find every subordinate this year monthly time
String [] monthName={" Jan ", "Feb.", "Mar.," "Apr.," "May,", "Jun.", "Jul.," ". ", "Sep.", "Oct., Nov., Dec." "};
For (the UserInfo m: members)
{
OutputDto outDto=new OutputDto ();
Double [] memberTime=new double [12].
Map Member=new HashMap (a);
String AD=m.g etAdAccount ();
for(int i=1; I & lt;=12; I++)
{
The Date firstDate=Helper. GetFirstDayOfMonth (yearInt, I);
The Date lastDate=Helper. GetLastDayOfMonth (yearInt, I);
The Date firstMondy=Helper. GetMondyDayOfDate (firstDate);
The Date lastMondy=Helper. GetMondyDayOfDate (lastDate);

List WBSList=taskService. GetWBSList (AD);

The Date startDate=firstMondy;
Double monthtime=0;
While (startDate. GetTime () & lt; .=lastMondy getTime ())
{
Double the daytime=0;
For (String WBS: WBSList)
{
List nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related