- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在尝试运行 Spring Boot 应用程序时,出现以下错误。
1:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userStatsController'
2:
Error creating bean with name 'scoreCardRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List.microservices.book.gamification.repository.ScoreCardRepository.findByUserIdOrderByScoreTimestampDesc(java.lang.Long)! No property timestamp found for type int! Traversed path: ScoreCard.score.
我使用的是H2数据库。
ScoreCardRepository.java
public interface ScoreCardRepository extends CrudRepository<ScoreCard, Long> {
@Query("SELECT SUM(s.score) FROM microservices.book.gamification.domain.ScoreCard s WHERE s.userId = :userId GROUP BY s.userId")
int getTotalScoreForUser(@Param("userId") final Long userId);
@Query("SELECT NEW microservices.book.gamification.domain.LeaderBoard(s.userId, SUM(s.score))"
+ "FROM microservices.book.gamification.domain.ScoreCard s "
+ "GROUP BY s.userId ORDER BY SUM(s.score) DESC")
List<LeaderBoardRow> findFirst10();
List<ScoreCard> findByUserIdOrderByScoreTimestampDesc(Long userId);
}
ScoreCard.java
@Entity
public class ScoreCard {
public static final int DEFAULT_SCORE = 20;
@Id
@GeneratedValue
@Column(name = "CARD_ID")
private Long cardId;
@Column(name = "USER_ID")
private Long userId;
@Column(name = "ATTEMPT_ID")
private Long attemptId;
@Column(name = "SCORE_TS")
private long scoreTimeStamp;
@Column(name = "SCORE")
private int score;
public ScoreCard() {
}
public ScoreCard(Long userId, Long attemptId) {
this.cardId = null;
this.userId = userId;
this.attemptId = attemptId;
this.scoreTimeStamp = System.currentTimeMillis();
this.score = DEFAULT_SCORE;
}
public Long getCardId() {
return cardId;
}
public Long getUserId() {
return userId;
}
public Long getAttemptId() {
return attemptId;
}
public long getScoreTimeStamp() {
return scoreTimeStamp;
}
public int getScore() {
return score;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((attemptId == null) ? 0 : attemptId.hashCode());
result = prime * result + ((cardId == null) ? 0 : cardId.hashCode());
result = prime * result + score;
result = prime * result + (int) (scoreTimeStamp ^ (scoreTimeStamp >>> 32));
result = prime * result + ((userId == null) ? 0 : userId.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ScoreCard other = (ScoreCard) obj;
if (attemptId == null) {
if (other.attemptId != null)
return false;
} else if (!attemptId.equals(other.attemptId))
return false;
if (cardId == null) {
if (other.cardId != null)
return false;
} else if (!cardId.equals(other.cardId))
return false;
if (score != other.score)
return false;
if (scoreTimeStamp != other.scoreTimeStamp)
return false;
if (userId == null) {
if (other.userId != null)
return false;
} else if (!userId.equals(other.userId))
return false;
return true;
}
@Override
public String toString() {
return "ScoreCard [cardId=" + cardId + ", userId=" + userId + ", attemptId=" + attemptId + ", scoreTimeStamp="
+ scoreTimeStamp + ", score=" + score + "]";
}
}
UserStatsController.java
@RestController
@RequestMapping("/stats")
public class UserStatsController {
private GameService gameService;
@Autowired
public UserStatsController(GameService gameService) {
this.gameService = gameService;
}
@GetMapping
public GameStats getStatsForUser(@RequestParam("userId") Long userId) {
return gameService.retrieveStatsForUser(userId);
}
}
应用程序属性
server.port=8081
spring.h2.console.enabled=true
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:h2:file:~/gamification;DB_CLOSE_ON_EXIT=FALSE;
spring.jpa.properties.hibernate.show_sql=true
最佳答案
您应该将findByUserIdOrderByScoreTimestampDesc
更改为findByUserIdOrderByScoreTimeStampDesc
。
说明:实体类的属性必须与默认命名策略匹配(除非专门配置)
我希望这能起作用。
您的实体类的属性名称为 scoreTimeStamp
(时间戳单词的大写),但在方法声明中,它是 ScoreTimestamp
(时间戳单词的小写) )。
PS:根据您在问题中提供的信息和以下评论,这应该只是问题所在。
关于java - 找不到 int 类型的属性时间戳!走过的路径 : ScoreCard. 分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57783356/
给定一个带有多个 date_time 戳的字符串,我想 提取第一个戳及其前面的文本 候选字符串可以有一个或多个时间戳 后续的 date_time 戳记将被 sep="-" 隔开 后续date_time
是否可以合并从相机拍摄的文本和照片?我想在照片上标记日期和时间,但我在 Google 上找不到任何内容。 最佳答案 使用下面的代码来实现你所需要的。 Bitmap src = Bitm
有没有办法通过 Graph API 戳另一个用户?基于this post ,并使用 Graph Explorer ,我发布到“/USERID/pokes”,我已经授予它(Graph API 应用程序和
我有两个向左浮动的元素。一个是 body 的第一个 child ,另一个是容器的第一个 child ,容器是 body 的第二个 child 。 ...
我是一名优秀的程序员,十分优秀!