这里不允许注释

And*_*310 9 spring annotations intellij-idea spring-data-jpa

我正在创建一个实现JpaRepository的UserRepository,并与User实体一起使用.我需要一种方法来更新用户名.我决定在@Query的帮助下完成它.但它的标志是Intellij.这是我的存储库代码:

@Repository
public interface UserRepository extends JpaRepository<User, Long> {

@Modifying
@Query(value = "update User user set user.name= %?username"))
void updatingUser(@Param(value = "username") String username);
}
Run Code Online (Sandbox Code Playgroud)

对于实体:

@Entity
@Table(name = "users")
public class User {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "user_id")
private Long id;

@NotNull
@Column(name = "user_name")
private String username;
}
Run Code Online (Sandbox Code Playgroud)

我遇到了这样一个问题:"这里不允许注释"Intellij Idea说道并用@Query注释标记了这一行.这让我感到困惑

And*_*310 9

对不起大家.对于我来说,在这一行的末尾写双引号真是太愚蠢了.但我实际上不明白为什么Intellij没有注意到这一点,但开始用另一个错误标记这一行

  • 完全不相关的问题仅通过意识到此错误可能由在线上的其他问题触发而得以解决。谢谢。 (2认同)

Luk*_*nzo 9

就我而言,我不小心输入了“;” 在@Query的末尾。可能会帮助别人。

  • 我犯了同样的错误,删除了;现在代码编译成功。 (2认同)