如何使用RestTemplate提交表单参数
@PostMapping(value = "/teacherlogin", produces = "application/json")
public String teacherLogin(@RequestParam("username") String username,
@RequestParam("password") String password){
MultiValueMap<String, String> mulmap = new LinkedMultiValueMap<>();
mulmap.add("username",username);
mulmap.add("password",password);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap> requestEntity = new HttpEntity<>(mulmap,headers);
ResponseEntity<ResponseDTO> responseEntity = restTemplate.postForEntity("http://localhost:8888/studentSys/test/logintest", requestEntity, ResponseDTO.class);
String status = responseEntity.getBody().getStatus();
if("failure".equals(status))
return "TeacherLoginPage";
return "TeacherMainPage";
}