:无法将类型"java. lang. String"的值转换为所需类型"java. lang. Integer";嵌套异常是java. lang. NumberFormatException:

laik7k3q  于 2023-01-07  发布在  Java
关注(0)|答案(1)|浏览(301)

我正在尝试创建一个方法,它会返回一个包含6个随机数的数组,但我一直被这个问题所困扰:

There was an unexpected error (type=Bad Request, status=400).
Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'; nested exception is java.lang.NumberFormatException: For input string: "game12"
org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'; nested exception is java.lang.NumberFormatException: For input string: "game12"

这些是我的方法

@PostMapping("/game12")
public ResponseEntity<Game> shuffleNumbers(){
    List<Integer> game=new ArrayList<>();
    Integer[] shuffled= postingShuffledGame();
    game.add(shuffled[0]);
    game.add(shuffled[1]);
    game.add(shuffled[2]);
    game.add(shuffled[3]);
    game.add(shuffled[4]);
    game.add(shuffled[5]);
    Game finalGame=new Game(game,12);
    repo.save(finalGame);
    return ResponseEntity.ok().body(finalGame);
}

public Integer[] postingShuffledGame() {
    Integer[] numbers= {1,2,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,56,57,58,59,60};
    List<Integer> intList=Arrays.asList(numbers);
    Collections.shuffle(intList);
    intList.toArray(numbers);
    return numbers;
}

我相信问题出在这两个中的一个,但是如果这里一切正常,这是我的完整代码:https://github.com/vitoriaacarvalho/jogando-na-mega-sena/tree/main/src/main/java/com/vitoria
非常感谢所有想帮忙的人!

v2g6jxz6

v2g6jxz61#

如错误所示,请求是错误的。你能给我看看请求吗?
尝试复制相同的错误,但得到- org.h2.jdbc.JdbcSQLSyntaxErrorException:未找到列“GAME_GAME_ID”; SQL语句:插入到game_numbers(game_game_id,游戏)值(?,?)
这是由GameController.java:74行引起的。忽略数据库错误,在注解并重试后,它工作-see image
但在此之前必须修复数据库错误。

相关问题