Spring RestTemplate使用REST principals与HTTP服务器通信。它使用HTTP动词,例如GET、POST、HEAD、PUT、DELETE 等。RestTemplate 提供了不同的通信方法,这些方法将接受 URI 模板、URI 变量、响应类型和请求对象作为参数。
package com.javainterviewpoint;
import java.util.List;
import java.util.Map;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;
public class StudentRestTemplateClient
{
public static final String REST_BASE_URI = "http://localhost:8080";
static RestTemplate restTemplate = new RestTemplate();
/** POST **/
public static void createStudent()
{
Student student = new Student();
student.setId(4);
student.setName("JIP4");
student.setAge(44);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
// headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
HttpEntity entity = new HttpEntity<>(student, headers);
restTemplate.postForObject(REST_BASE_URI + "/student", entity, Student.class);
}
/** GET **/
private static void getStudent(int id)
{
Student student = restTemplate.getForObject(REST_BASE_URI + "/student/" + id, Student.class);
System.out.println("**** Student with id : " + id + "****");
System.out
.println("Id :" + student.getId() + " Name : " + student.getName() + " Age : " + student.getAge());
}
public static void getAllStudents()
{
List
输出 :
16:29:41.159 [main] DEBUG org.springframework.web.client.RestTemplate - Created POST request for "http://localhost:8080/student"
16:29:41.227 [main] DEBUG org.springframework.web.client.RestTemplate - Setting request Accept header to [application/json, application/*+json]
16:29:41.258 [main] DEBUG org.springframework.web.client.RestTemplate - Writing [Student [id=4, name=JIP4, age=44]] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@91e32e]
16:29:41.402 [main] DEBUG org.springframework.web.client.RestTemplate - POST request for "http://localhost:8080/student" resulted in 204 (null)
16:29:41.404 [main] DEBUG org.springframework.web.client.RestTemplate - Created GET request for "http://localhost:8080/students"
16:29:41.446 [main] DEBUG org.springframework.web.client.RestTemplate - Setting request Accept header to [application/json, application/*+json]
16:29:41.460 [main] DEBUG org.springframework.web.client.RestTemplate - GET request for "http://localhost:8080/students" resulted in 200 (null)
16:29:41.460 [main] DEBUG org.springframework.web.client.RestTemplate - Reading [interface java.util.List] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@91e32e]
**** All Students ****
Id : id=1 Name=JIP1 Age=11
Id : id=2 Name=JIP2 Age=22
Id : id=3 Name=JIP3 Age=33
Id : id=4 Name=JIP4 Age=44
16:29:41.490 [main] DEBUG org.springframework.web.client.RestTemplate - Created GET request for "http://localhost:8080/student/2"
16:29:41.490 [main] DEBUG org.springframework.web.client.RestTemplate - Setting request Accept header to [application/json, application/*+json]
16:29:41.496 [main] DEBUG org.springframework.web.client.RestTemplate - GET request for "http://localhost:8080/student/2" resulted in 200 (null)
16:29:41.497 [main] DEBUG org.springframework.web.client.RestTemplate - Reading [class com.javainterviewpoint.Student] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@91e32e]
**** Student with id : 2****
Id :2 Name : JIP2 Age : 22
16:29:41.498 [main] DEBUG org.springframework.web.client.RestTemplate - Created PUT request for "http://localhost:8080/student"
16:29:41.499 [main] DEBUG org.springframework.web.client.RestTemplate - Writing [Student [id=5, name=JIP555555, age=55]] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@91e32e]
16:29:41.532 [main] DEBUG org.springframework.web.client.RestTemplate - PUT request for "http://localhost:8080/student" resulted in 200 (null)
16:29:41.533 [main] DEBUG org.springframework.web.client.RestTemplate - Created DELETE request for "http://localhost:8080/student/5"
16:29:41.540 [main] DEBUG org.springframework.web.client.RestTemplate - DELETE request for "http://localhost:8080/student/5" resulted in 204 (null)
返回做IO数目最多的50条语句以及它们的执行计划。
select top 50
(total_logical_reads/execution_count) as avg_logical_reads,
(total_logical_writes/execution_count) as avg_logical_writes,
(tot
The CUDA 5 Release Candidate is now available at http://developer.nvidia.com/<wbr></wbr>cuda/cuda-pre-production. Now applicable to a broader set of algorithms, CUDA 5 has advanced fe
Essential Studio for WinRT界面控件包含了商业平板应用程序开发中所需的所有控件,如市场上运行速度最快的grid 和chart、地图、RDL报表查看器、丰富的文本查看器及图表等等。同时,该控件还包含了一组独特的库,用于从WinRT应用程序中生成Excel、Word以及PDF格式的文件。此文将对其另外一个强大的控件——网格控件进行专门的测评详述。
网格控件功能
1、
Project Euler是个数学问题求解网站,网站设计的很有意思,有很多problem,在未提交正确答案前不能查看problem的overview,也不能查看关于problem的discussion thread,只能看到现在problem已经被多少人解决了,人数越多往往代表问题越容易。
看看problem 1吧:
Add all the natural num
Adding id and class names to CMenu
We use the id and htmlOptions to accomplish this. Watch.
//in your view
$this->widget('zii.widgets.CMenu', array(
'id'=>'myMenu',
'items'=>$this-&g
Given a collection of integers that might contain duplicates, nums, return all possible subsets.
Note:
Elements in a subset must be in non-descending order.
The solution set must not conta