遇到这个问题:

cannot find symbol method of(@javax.validation.constraints.NotEmpty java.lang.String)

应用代码

package com.example.demo_article_manage.entity;

import lombok.Data;

import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;

@Entity
@Data
public class Article extends BaseEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    @Column(nullable = false, unique = true)
    @NotEmpty(message = "标题不能为空")
    private String title;

    @Column(nullable = false)
    private String body;
}

实际是缺少依赖,在POM.xml中添加如下依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-validation</artifactId>
</dependency>

更新依赖,问题解决。

又遇到了这个问题

Spring - Cannot resolve MVC “view” thymeleaf

返回这些问题

{
    "timestamp": "2021-06-08T03:11:33.133+00:00",
    "status": 404,
    "error": "Not Found",
    "message": "No message available",
    "path": "/article/add"
}

两个原因:一个是没有引入thymeleaf依赖,另一个thymeleaf版本不兼容。最好不要制定版本,直接添加如下依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

Tags: Java, spring

Related Posts:

Leave a Comment