I need your help and advice. This is my first project in jersey. I don't know much about this topic. I'm still learning. I created my school project. But I have some problems on the web service side. Firstly I should explain my project. I have got 3 tables in my database. Movie,User,Ratings
Here my Movie table columns. I will ask you some points about Description column of the Movie table. I will use these methods to these columns.
Movie= Description (get,put,post and delete) I have to use all methods in this page.
movieTitle (get)
pictureURL (get,put)
generalRating (get,post)
I built my Description page. But I'm not sure if its working or not .(My database is not ready to check them). Here is my page. I wrote this page, looking at the example pages. Can u help me to find the problems and errors. I just want to do simple methods get(just reading data), post(update existing data), put(create new data), delete(delete specific data) these things.What should I do now, is my code okay or do you have alternative advice? :( I need your help guys ty
package com.vogella.jersey.first;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.List;
import javax.ejb.*;
import javax.persistence.*;
import javax.ws.rs.*;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.OPTIONS;
import javax.ws.rs.PUT;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
@Path("/Movie/Description")
public class Description {
private Moviedao moviedao = new Moviedao();
@GET
@Path("/Description/")
@Produces(MediaType.APPLICATION_XML)
public Description getDescriptionID(@PathParam("sample6") string sample6){
return moviedao.getDescriptionID(id);
}
@POST
@Path("/Description/")
@Produces(MediaType.APPLICATION_XML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void updateDescription(@PathParam("sampleID")int sampleID,
@PathParam("sample2Description")string sample2Description)
throws IOException {
Description description = new Description (sampleID, sample2Description);
int result = moviedao.updateDescription(description);
if(result == 1){
return SUCCESS_RESULT;
}
return FAILURE_RESULT;
}
@PUT
@Path("/Description")
@Produces(MediaType.APPLICATION_XML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public String createUser(@FormParam("sample8ID") int sample8ID,
@FormParam("sample8Description") String sample8Description,
@Context HttpServletResponse servletResponse) throws IOException{
Description description = new Description (sample8ID, sample8Description);
int result = movidao.addDescription(description);
if(result == 1){
return SUCCESS_RESULT;
}
return FAILURE_RESULT;
}
@DELETE
@Path("/Description/{descriptionID}")
@Produces(MediaType.APPLICATION_XML)
public String deleteUser(@PathParam("descriptionID") int descriptionID){
int result = moviedao.deleteDescription(descriptionID);
if(result == 1){
return SUCCESS_RESULT;
}
return FAILURE_RESULT;
}
@OPTIONS
@Path("/Description")
@Produces(MediaType.APPLICATION_XML)
public String getSupportedOperations(){
return "<operations>GET, PUT, POST, DELETE</operations>";
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…