Reputation: 2202
I'm experiencing very weird behaviour in my back-end.
On my front-end, which is written in angular 4, I'm calling method from back-end that will acquire all employees for specific organization unit from specific database table. Also, I'm calling method that fills MatSelect with options from back-end app.
CODE:
Back-end Controller:
@RequestMapping(value = "/orgid/{orgid}", produces = "application/json")
public Iterable<Employee> getEmployeeByOrgId(@PathVariable("orgid") String orgid, HttpServletRequest req){
Iterable<Employee> getEmpByOrgId = eDao.findEmployeesByOrgNameId(orgid);
return getEmpByOrgId;
}
Back-end DAO:
@Query("SELECT new model.Employees(p.id, p.firstName, p.lastName, p.organizationName, p.subOrganizationName, p.mobilephoneNumber, p.telephoneNumber, p.smallImage, p.jobTitle) FROM Employee p WHERE p.orgId = :orgId ORDER by p.lastName")
public Iterable<Employee> findEmployeesByOrgNameId(@Param("orgId") String orgId);
Front-end Service:
fetchEmployeesByOrg(org): Observable<Employees[]>{
const url ="employees/orgid/"+org;
return this.http.get<Employees[]>(url);
}
Front-end Component:
fetchAllEmployeesByOrgId(org){
this.orgId = org.id.toString();
console.log(typeof this.orgId);
this.fetch.fetchEmployeesByOrg(this.orgId).subscribe(res => {
this.EmployeesByOrg = res;
console.log(this.EmployeesByOrg);
})
}
Front-end html:
<mat-select placeholder="Choose it">
<mat-option *ngFor="let org of this.orgUnits" [value]="org.value" (click)="fetchAllEmployeesByOrgId(org)">
{{ org.orgName }}
</mat-option>
How my url looks when I click on specific option: employees/orgid/166
Problem:
I'm getting java.lang.IllegalArgumentException: Parameter value [166] did not match expected type [java.lang.Integer (n/a)]
As mentioned above, I'm expecting string in back-end and also, I'm providing string within url.
Maybe it's problem inside of custom query or something? Any help would be great.
Upvotes: 1
Views: 421
Reputation: 1649
The problem is that the @param
arg is injected as a String
into the query, so the method signature must be changed :
findEmployeesByOrgNameId(@Param("orgId") Integer orgId)
and if you passe a String
to you controller (that you are sure is parsable to Integer
) you can convert the param to an Integer
then call the dao method :
eDao.findEmployeesByOrgNameId(Integer.valueOf(orgid));
Upvotes: 1