【问题标题】:Spring Boot newbie - Request method 'POST' not supportedSpring Boot新手 - 不支持请求方法“POST”
【发布时间】:2015-09-03 18:25:27
【问题描述】:

有很多类似的问题,我已经看过了,但仍然无法弄清楚我的问题是什么。非常感谢您的帮助。 这是我的控制器:

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

发布到 /game

【问题讨论】:

  • 能否也提供您的 Spring Boot 配置类?另外,您发布的网址是什么?
  • @geoand 当然,等一下

标签: spring spring-boot


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2018-06-03
    • 2020-03-31
    • 2016-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多