2017-04-24 14 views
0

我試圖使用POSTMAN訪問一個簡單的API,但每次它都會給404錯誤找不到。我能做些什麼來訪問我的API?使用POSTMAN訪問Spring RestApi(404找不到)

package api; 
import org.springframework.web.bind.annotation.RequestBody; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.RestController; 
import com.example.BloggApplication; 
import com.google.gson.Gson; 
import model.User; 
@RestController 
public class UserApi { 
    Gson gson = new Gson(); 
    @RequestMapping(value="api/createUser/", 
      method = RequestMethod.POST) 
    public int createUser(@RequestBody String json) { 
     User user = gson.fromJson(json, User.class); 
     BloggApplication.users.add(user); 
     return user.getId(); 
    } 
} 

這是我PostApi類,

我的主要類是在BloggApplication.java。

我打電話使用郵差,因爲這

http://localhost:8080/api/createUser/ 

的API,與身體

{"Content-Type" :"application/json", 
"userName" : "ali", 
"password" : "123456"} 

回答

0

我解決了這個問題,我把它包含了「springboot應用」上述其他類一級應用程序類。

src/main/java/application.java 
src/main/java/app/other classes