Spring Boot新手 - 不支持请求方法'POST'

时间:2015-09-03 10:03:47

标签: spring spring-boot

有很多类似的问题,我看过它们但仍然无法弄清楚我的问题是什么。非常感谢这方面的帮助。 这是我的控制者:

@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;
}

这是我的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
public class YatzyConfiguration {

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

发布到/游戏

1 个答案:

答案 0 :(得分:2)

您在value = "/{DiceDTO}"注释中不需要@RequestMapping,因为Spring认为它是路径的一部分。因此Spring实际上将POST请求映射到/ game / somenting path。

相关问题