2017-04-24 11 views
0

私はPOSTMANを使用して単純なapiにアクセスしようとしていますが、エラー404が見つからないときはいつでもそうです。私のAPIにアクセスするにはどうすればよいですか?POSTMAN(404 not found)を使用してSpring RestApiにアクセス

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(); 
    } 
} 

これは

私の主なクラスがBloggApplication.javaであり、私のPostApiクラスです。

私は私が1つのレベルの他のクラス上の "springbootアプリケーション" を含むApplicationクラスを移動し、問題を解決しました。ボディ

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

答えて

0

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

、このようPOSTMANを使用してAPIを呼び出します

src/main/java/application.java 
src/main/java/app/other classes 
関連する問題