[size=large][b]1. 整合RESTEasy和Jackson2 [/b][/size]
需要引入resteasy-jackson-provider.jar
[size=large][b]2.一个简单的Object[/b][/size]
[b][size=large]3. REST Service [/size][/b]
[size=large][b]4. RUN[/b][/size]
请求:http://localhost:8080/resteasy-example/hello/customer/json
[img]http://dl2.iteye.com/upload/attachment/0086/2669/4d8c323f-f11e-38a9-a55e-82d011e5fd5b.png[/img]
需要引入resteasy-jackson-provider.jar
[size=large][b]2.一个简单的Object[/b][/size]
package com.example.rest.resteasy.model;
public class Customer {
private int id;
private String firstName;
private String lastName;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
[b][size=large]3. REST Service [/size][/b]
package com.example.rest.resteasy.service;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import com.example.rest.resteasy.model.Customer;
@Path("/hello")
public class HelloWorldRestService {
@GET
@Path("/customer/json")
@Produces("application/json")
public Customer getProductInJSON() {
Customer customer = new Customer();
customer.setFirstName("first");
customer.setLastName("last");
customer.setId(100);
return customer;
}
}
[size=large][b]4. RUN[/b][/size]
请求:http://localhost:8080/resteasy-example/hello/customer/json
[img]http://dl2.iteye.com/upload/attachment/0086/2669/4d8c323f-f11e-38a9-a55e-82d011e5fd5b.png[/img]