2017-03-15 59 views
0

我的代碼看起來像這樣的工作:GET不會爲RESTful Web服務

@Path("/UserService") 
public class UserService { 
    UserDAO userDao = new UserDAO(); 
    private static final String SUCCESS_RESULT = "<result>success</result>"; 
    private static final String FAILURE_RESULT = "<result>failure</result>"; 

    @GET 
    @Path("/users") 
    @Produces(MediaType.APPLICATION_XML) 
    public List<User> getUsers() throws SQLException { 
     return userDao.getAllUsers(); 
    } 

    @GET 
    @Path("https://stackoverflow.com/users/{email}") 
    @Produces(MediaType.APPLICATION_XML) 
    public User getUser(@PathParam("email") String email) throws SQLException { 
     return userDao.getUser(email); 
    } 
} 

如果我嘗試以下URI:http://localhost:8080/Webservice/rest/UserService/users,我得到的所有用戶,這就是正確的。我的問題是,如果我叫http://localhost:8080/Webservice/rest/UserService/users/test(測試是一個人在數據庫中的電子郵件,沒有什麼變化

你知道爲什麼不起作用

更多的代碼:?

@XmlRootElement(name = "user") 
public class User implements Serializable { 
    private static final long serialVersionUID = 1L; 
    private String email = null; 
    private String vorname = null; 
    private String nachname = null; 
    private String gebDatum = null; 
    private String password = null; 
    private float kontostand = -1; 

    public User() { 
     super(); 
    } 

    public User(String email, String vorname, String nachname, String gebDatum, String password, float kontostand) { 
     super(); 
     this.email = email; 
     this.vorname = vorname; 
     this.nachname = nachname; 
     this.gebDatum = gebDatum; 
     this.password = password; 
     this.kontostand = kontostand; 
    } 

    public String getEmail() { 
     return email; 
    } 

    @XmlElement 
    public void setEmail(String email) { 
     this.email = email; 
    } 

    public String getVorname() { 
     return vorname; 
    } 

    @XmlElement 
    public void setVorname(String vorname) { 
     this.vorname = vorname; 
    } 

    public String getNachname() { 
     return nachname; 
    } 

    @XmlElement 
    public void setNachname(String nachname) { 
     this.nachname = nachname; 
    } 

    public String getGebDatum() { 
     return gebDatum; 
    } 

    @XmlElement 
    public void setGebDatum(String gebDatum) { 
     this.gebDatum = gebDatum; 
    } 

    public String getPassword() { 
     return password; 
    } 

    @XmlElement 
    public void setPassword(String password) { 
     this.password = password; 
    } 

    public float getKontostand() { 
     return kontostand; 
    } 

    @XmlElement 
    public void setKontostand(float kontostand) { 
     this.kontostand = kontostand; 
    } 

userDao我有以下幾種方法:

public List<User> getAllUsers() throws SQLException { 
     openConnection(
       "select u.email from user u") ; 

     if (rs != null) { 
      while (rs.next()) { 
       User u = new User(rs.getObject(1).toString(), rs.getObject(2).toString(), rs.getObject(3).toString(), 
         rs.getObject(4).toString(), rs.getObject(5).toString(), 
         Float.parseFloat(rs.getObject(6).toString())); 
       users.add(u); 
      } 
     } 
     closeConnection(); 

     return users; 
    } 

    public User getUser(String email) throws SQLException { 
     List<User> users = getAllUsers(); 
     for (User user : users) { 
      if (user.getEmail() == email) { 
       return user; 
      } 
     } 
     return null; 
    } 
+0

Trivial字符串比較問題。 – Mordechai

+0

我該如何解決這個問題? – hulapalu

+0

爲什麼你不使用Swagger API? –

回答