Reputation: 431
Here's my front-end code:
// the img64 here does received data from client with a long char sequence
console.log(img64);
axios.post(serverUrl + '/adminMng/adminFaceLogin',
{
username: username,
img64: img64
})
.then(res => {
console.log(res.data);
if (res.data.status == 200) {
alert("Face recognition successful! Click to confirm to enter the system");
window.location = app.adminIndexUrl;
} else {
alert(res.data.msg);
}
});
And the AdminLoginBO is :
public class AdminLoginBO {
private String username;
private String password;
private String image64;
// getter and setter
...
}
The AdminMngControllerApi is
@RequestMapping("/adminMng")
public interface AdminMngControllerApi {
@PostMapping("/adminFaceLogin")
GraceJSONResult adminFaceLogin(@RequestBody AdminLoginBO adminLoginBO,
HttpServletRequest request,
HttpServletResponse response);
}
And the implementing class of AdinMngControllerApi is:
@RestController
public class AdminMngController implements AdminMngControllerApi {
@Override
public GraceJSONResult adminFaceLogin(AdminLoginBO adminLoginBO, HttpServletRequest request,
HttpServletResponse response) {
String username = adminLoginBO.getUsername(); // this value is valid, eg: "andrew"
String image64 = adminLoginBO.getImage64(); // but this value is null
//face login logics
...
}
}
Both the params from front-end received valid value from client, but when it goes into backend, the "username" variable received the value, but the "img64" variable is null.
Upvotes: 0
Views: 23
Reputation: 6358
That's because the name of the object sent at the front end is img64, and the AdminLoginBO
expects a image64
as a name. For the username, both of the object matches the name.
You can change img64: img64
for image64: img64
Upvotes: 1