Home > Back-end >  Spring - data - how jpa with @ Query multi-table Query, return to the map
Spring - data - how jpa with @ Query multi-table Query, return to the map

Time:01-21

@ Query (" select s.u serid, supachai panitchpakdi layeddury, s.c ourseid, s.v ideoid, l.n ame as videoname, l.c licknum, l.u ploadtime, l.d ownloadnum, l.i mahttppath, l.v idhttppath, their lives ecommend from AppStudyRecodTable s, LoadVideoTable l where s.u serid=? And l.i d=s.v ideoid ")
Public List FindByUserid (int userid);
I checked two tables, but the return value is what, at ordinary times the return value is defined Entiry, but even table, is impossible to return to the Entity,
So I returned to the List , but the result is not ideal, and return the following
{
"Errormsg", "success",
"Data" : [

1000,
"23",
2,
8,
"Drums",
5,
"The 2016-12-13 04:35:19 \ n",
0,
"Http://1608k8d317.iask.in:80/1480667720159-c100.png",
"Http://1608k8d317.iask.in:80/1480667718639- [2] Chen 2 G YN life. 01 set _hd mp4",
"0"
],

1000,
"45",
1,
4,
"Tax 232,"
1,
"The 2016-12-02 04:35:19,"
0,
"Http://1608k8d317.iask.in:80/1480667720159-c100.png",
"Http://1608k8d317.iask.in:80/1480667718639- [2] Chen 2 G YN life. 01 set _hd mp4",
"0"
]
],
"Errorcode" : "0"
}
This is a list, no map corresponding key, how to let him return to the map, the map is the key to select s.u serid, supachai panitchpakdi layeddury, the userid? At the situation

CodePudding user response:

With a new map,
@ Query (" select new map (s.u serid, supachai panitchpakdi layeddury, s.c ourseid, s.v ideoid, l.n ame as videoname, l.c licknum, l.u ploadtime, l.d ownloadnum, l.i mahttppath, l.v idhttppath, their lives ecommend) from AppStudyRecodTable s, LoadVideoTable l where s.u serid=? And l.i d=s.v ideoid ")
Public List FindByUserid (int userid);

CodePudding user response:

Excuse me to solve it is also the same problem

CodePudding user response:

The building Lord solved

CodePudding user response:

Didn't solve, I can only in the integration of a set of Mybatis architecture, uncomfortable

CodePudding user response:

Very not easy to see a similar one,,, the result didn't answer the building Lord

CodePudding user response:

No, don't return, type safety limit,,,, true to use other methods, or returns the Object to turn a a strong again

CodePudding user response:

To ask how to solve? I also encountered this problem

CodePudding user response:

Return List CodePudding user response:

You can use List<?> FindByUserid (int userid), and finally transformed to obtain desired values

CodePudding user response:

reference 1st floor a878102433 response:
use new map,
@ Query (" select new map (s.u serid, supachai panitchpakdi layeddury, s.c ourseid, s.v ideoid, l.n ame as videoname, l.c licknum, l.u ploadtime, l.d ownloadnum, l.i mahttppath, l.v idhttppath, their lives ecommend) from AppStudyRecodTable s, LoadVideoTable l where s.u serid=? And l.i d=s.v ideoid ")
Public List FindByUserid (int userid);

@ Query (" select new map (s.u serid as userid,...
")Behind his fill, don't write as XXXX, out of the map key value is 1, 2, 3... , general is such, just also touch this problem last night

CodePudding user response:

List Company=companyService. FindAllDemp ();
JSONArray JSONArray=JSONArray. FromObject (company);
Equivalent to json no

CodePudding user response:

AppStudyRecodTable, LoadVideoTable two tables should be at the time of entity class, if is a one-to-one relationship in AppStudyRecodTable entity class to add
@ OneToOne
@ JoinColumn (name="video_id")
Private LoadVideoTable LoadVideoTable;
Then the query List< directly; AppStudyRecodTable> FindByUserId (String id); Went, to obtain LoadVideoTable the contents of the table to create AppStudyRecodTable object. GetloadVideoTable,,,,

CodePudding user response:

@ Query (value="https://bbs.csdn.net/topics/XXXXXX", nativeQuery=true)
List GetSysPermissionByUserName ();
I use return list To solve the

CodePudding user response:

Take out a SQL List ,
The control to the list, the type Object into the Map type
You can refer to this code
List ResultList=new ArrayList<> (a);
ListFor (Object row: result) {
Object [] rowArray=(Object []) row;
Map MapArr=new HashMap (a);
MapArr. Put (" id ", rowArray [0]).
MapArr. Put (" name ", rowArray [1]).
MapArr. Put (" sex ", rowArray [2]).
ResultList. Add (mapArr);
}
Return resultList;

So the front desk to get the List is the key: value type of the
{
"Id" : "111",
"Name" : ABC,
"Sex" : 1
},
{
"Id" : "222",
"Name" : ABC,
"Sex" : 0
},

Or build a DTO, use dtos to pick up this List should be also can

CodePudding user response:

According to the writing of the first floor error, UnsatisfiedDependencyException, who has a better treatment method

CodePudding user response:

I change the new map to the new map is not an error, also can check whether are entities defined inside field, after all this is to provide the implementation of the jpa, estimated to abide by certain regulations

CodePudding user response:

This
@ Query (value="new https://bbs.csdn.net/topics/select com. Kevin. Demo2. Model. UserVo (u.i d, u.n ame, Arthur c. ityName) from TkUser u LEFT the JOIN" +
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related