看代码:
package test.com.wondersgroup.hs.test.controller;
import org.junit.Test;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
public class UserControllerTest {
@Test
public void testCreateUser(){
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
form.add("userName", "tom");
form.add("password", "123456");
form.add("age", "45");
String result = restTemplate.postForObject("http://localhost:8080/SpringmvcDemo/users.html", form, String.class);
System.out.println(result);
}
}