Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring IsMongOproject.controller.ScoreController中方法createScore的参数0需要类型为';项目得分为#x27;_Spring_Mongodb_Spring Boot - Fatal编程技术网

Spring IsMongOproject.controller.ScoreController中方法createScore的参数0需要类型为';项目得分为#x27;

Spring IsMongOproject.controller.ScoreController中方法createScore的参数0需要类型为';项目得分为#x27;,spring,mongodb,spring-boot,Spring,Mongodb,Spring Boot,我在MongoDb中使用了SpringBootRESTAPI。 我有四门课,球员课,游戏课,历史课和分数课。 我使用了带有Spring数据和MongoDB的嵌入式文档,在我的项目中,我想为现有玩家和游戏代码创建一个新的POST方法。 但我有这个错误,不明白为什么 分数等级: package thesisMongoProject; import java.util.Date; import java.util.List; import javax.validation.constrai

我在MongoDb中使用了SpringBootRESTAPI。 我有四门课,球员课,游戏课,历史课和分数课。 我使用了带有Spring数据和MongoDB的嵌入式文档,在我的项目中,我想为现有玩家和游戏代码创建一个新的POST方法。 但我有这个错误,不明白为什么

分数等级:

    package thesisMongoProject;

import java.util.Date;
import java.util.List;

import javax.validation.constraints.NotBlank;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import com.fasterxml.jackson.annotation.JsonView;

@Document(collection = "score")
public class Score {
    @Id
    @NotBlank
    @JsonView(Views.class)
    private String scoreID;
    @NotBlank
    @JsonView(Views.class)
    private String score;
    @NotBlank
    @JsonView(Views.class)
    private Player player;
    @NotBlank
    @JsonView(Views.class)
    private Games gamecode;
    @JsonView(Views.class)
    private Date date;
    private List<History> history;



    public Score(@NotBlank String scoreID, @NotBlank String score, @NotBlank Player player, @NotBlank Games gamecode,
            Date date, List<History> history) {
        super();
        this.scoreID = scoreID;
        this.score = score;
        this.player = player;
        this.gamecode = gamecode;
        this.date = date;
        this.history = history;
    }
    public String getScoreID() {
        return scoreID;
    }
    public void setScoreID(String scoreID) {
        this.scoreID = scoreID;
    }
    public String getScore() {
        return score;
    }
    public void setScore(String score) {
        this.score = score;
    }
    public Player getPlayer() {
        return player;
    }
    public void setPlayer(Player player) {
        this.player = player;
    }
    public Games getGamecode() {
        return gamecode;
    }
    public void setGamecode(Games gamecode) {
        this.gamecode = gamecode;
    }
    public Date getDate() {
        return date;
    }
    public void setDate(Date date) {
        this.date = date;
    }
    public List<History> getHistory() {
        return history;
    }
    public void setHistory(List<History> history) {
        this.history = history;
    }







}
游戏课:

    package thesisMongoProject;

import javax.validation.constraints.NotBlank;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;


@Document(collection = "game")
public class Games {
    @Id
    @NotBlank
    private String code;
    @NotBlank
    private String title;
    @NotBlank
    private String software_house;
    @NotBlank
    private String version;
    @NotBlank
    private String release_year;
    public Games(@NotBlank String code, @NotBlank String title, @NotBlank String software_house,
            @NotBlank String version, @NotBlank @NotBlank @NotBlank String release_year) {
        super();
        this.code = code;
        this.title = title;
        this.software_house = software_house;
        this.version = version;
        this.release_year = release_year;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getSoftware_house() {
        return software_house;
    }
    public void setSoftware_house(String software_house) {
        this.software_house = software_house;
    }
    public String getVersion() {
        return version;
    }
    public void setVersion(String version) {
        this.version = version;
    }
    public @NotBlank String getRelease_year() {
        return release_year;
    }
    public void setRelease_year(@NotBlank String release_year) {
        this.release_year = release_year;
    }
    @Override
    public String toString() {
        return "Games [code=" + code + ", title=" + title + ", software_house=" + software_house + ", version="
                + version + ", release_year=" + release_year + "]";
    }


}
历史课:

    package thesisMongoProject;

import java.util.Date;

public class History {  

        private String score;
        private Date date;




        public History(String score, Date date) {
            super();
            this.score = score;
            this.date = date;
        }



        public String getScore() {
            return score;
        }



        public void setScore(String score) {
            this.score = score;
        }



        public Date getDate() {
            return date;
        }



        public void setDate(Date date) {
            this.date = date;
        }



        @Override
        public String toString() {
            return "History [score=" + score + ", date=" + date + "]";
        }








}
视图类:

    package thesisMongoProject;

public class Views {
    public static class Creat{}

}
分数存储库:

    package thesisMongoProject.Repository;

import java.util.List;

import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.stereotype.Repository;

import thesisMongoProject.Games;
import thesisMongoProject.Player;
import thesisMongoProject.Score;

@Repository
public interface ScoreRepository extends MongoRepository<Score, String>{


    public List<Score> findByScore(String score);

    @Query("{'player.nickname':?0}")
    public List<Score> findByPlayerName(Player player);

    @Query("{'gamecode.code':?0}")
    public List<Score> findByGameCode(Games game);
}

您能帮我一下吗,我的错误是什么,请

问题是,在Score Controller中定义了一个Score Repository实例之后

 @RestController
    @RequestMapping("/score")
    public class ScoreController {
        @Autowired
        private ScoreRepository  srepo;
        @Autowired

我在未使用的情况下编写了一个@Autowired注释,因此当我删除这个未使用的@Autowired注释时,一切都运行良好。

问题是,在定义了分数存储库实例之后,在分数控制器中

 @RestController
    @RequestMapping("/score")
    public class ScoreController {
        @Autowired
        private ScoreRepository  srepo;
        @Autowired

我在未使用的情况下编写了一个@Autowired注释,因此当我删除这个未使用的@Autowired注释时,一切都运行良好。

编译成功了吗?您必须为
@PostMapping
指定一个映射名称。例如
@PostMapping(“/create”)
。然后在postman或swagger中将它称为
“/score/create”
,这是你的智慧——它没有成功编译。我的控制台有一个错误。此错误:IsMongOproject.controller.ScoreController中方法createScore的参数0需要一个类型为“TheIsMongOproject.Score”的bean,该bean无法为Post找到。在RequestMapping中,我指出“/create”,因此我认为它在PostMapping中并不重要,我不知道映射名称。顺便说一句,我没有成功编译任何技术?您必须为
@PostMapping
指定一个映射名称。例如
@PostMapping(“/create”)
。然后在postman或swagger中将它称为
“/score/create”
,这是你的智慧——它没有成功编译。我的控制台有一个错误。此错误:IsMongOproject.controller.ScoreController中方法createScore的参数0需要一个类型为“TheIsMongOproject.Score”的bean,该bean无法为Post找到。在RequestMapping中,我指出“/create”,因此我认为它在PostMapping中并不重要,我不知道映射名称。顺便说一句,我做了,但没什么变化
Description:

Parameter 0 of method createScore in thesisMongoProject.controller.ScoreController required a bean of type 'thesisMongoProject.Score' that could not be found.

The injection point has the following annotations:
    - @org.springframework.web.bind.annotation.RequestBody(required=true)
    - @com.fasterxml.jackson.annotation.JsonView({thesisMongoProject.Views.class})


Action:

Consider defining a bean of type 'thesisMongoProject.Score' in your configuration.
 @RestController
    @RequestMapping("/score")
    public class ScoreController {
        @Autowired
        private ScoreRepository  srepo;
        @Autowired