2015-09-03 44 views
0

有很多類似的問題,我看過他們,但仍然無法弄清楚我的問題是什麼。真的很感謝幫助。 這是我的控制器:Spring Boot新手 - 不支持請求方法'POST'

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

發佈到/遊戲

+0

你還可以提供你的Spring Boot配置類嗎?另外,您發佈的網址是什麼? – geoand

+0

@geo,當然,只需一秒 – Aydin

回答

2

你不需要value = "/{DiceDTO}"@RequestMapping註釋中,因爲Spring認爲它是p ath的一部分。所以Spring實際上將POST請求映射到/ game/somenting路徑中。

相關問題