この例を使用してRESTサービスを呼び出す方法を学習しようとしていますが、このコードを配置すると、日食がorg.example.Customerを認識していないため、エラーが発生し ます。。定義顧客顧客のエラー。プロジェクトにインポートするにはどうすればよいですか?私は日食の提案を使用しようとしましたが、成功しませんでした。(プロジェクトの設定などを修正)
import java.util.List;
import javax.ws.rs.core.MediaType;
import org.example.Customer;
import com.sun.jersey.api.client.*;
public class JerseyClient {
public static void main(String[] args) {
Client client = Client.create();
WebResource resource =
client.resource("http://localhost:8080/CustomerService/rest/customers");
// Get response as String
String string = resource.path("1")
.accept(MediaType.APPLICATION_XML)
.get(String.class);
System.out.println(string);
// Get response as Customer
Customer customer = resource.path("1") ------"*Here is the error in customer*-------
.accept(MediaType.APPLICATION_XML)
.get(Customer.class);
System.out.println(customer.getLastName() + ", "+ customer.getFirstName());
// Get response as List<Customer>
List<Customer> customers = resource.path("findCustomersByCity/Any%20Town")
.accept(MediaType.APPLICATION_XML)
.get(new GenericType<List<Customer>>(){});
System.out.println(customers.size());
}
}
このブログのコードを使用しました
http://blog.bdoughan.com/2010/08/creating-restful-web-service-part-55.html