Aydin
Aydin

Reputation: 331

Spring Boot newbie - Request method 'POST' not supported

There are a lot of similar questions to this, I have looked at them but still couldn't figure out what my problem is. Would really appreciate help with this. This is my controller:

@RestController
@RequestMapping(value = "/game")
public class YatzyController {

@Autowired
private Games games;

@RequestMapping(value = "/{DiceDTO}", method = RequestMethod.POST)
public GameState putGameState(@ModelAttribute("DiceDTO") DiceDTO diceDTO) {
  return null;
}

And this is my HTML:

<form method="post" enctype='application/json' action="/game">
<button type="button" onclick="rollDice()">Roll dice</button>
  <div>
    <input type="text" id="dice1" disabled>
    <input type="checkbox" id="keepdice1" value="Keep">
  </div>
  <div>
    <input type="text" id="dice2" disabled>
    <input type="checkbox" id="keepdice2" value="Keep">
  </div>
  <input type="submit">
</form>

Configuration class:

@Configuration
public class YatzyConfiguration {

  @Bean
  public Games games(){
    return new Games();
  }
}

Posting to /game

Upvotes: 0

Views: 398

Answers (1)

Alexander Tokarev
Alexander Tokarev

Reputation: 2763

You don't need value = "/{DiceDTO}" in @RequestMapping annotation, because Spring considers it as path's part. So Spring actually maps POST request to /game/somenting path in your case.

Upvotes: 2

Related Questions