[Jstl等于验证弹簧中的String

问题描述 投票:0回答:1

我正在使用属性制作多语言错误警报以进行验证(注解和Spring)我想检查它的@NotBlank和@Size但是即使我使用

<c:set var="checkusername"><form:errors path="username"/></c:set>
<c:if test="${checkusername == 'username.id'}">
   div class="loi"><s:message code="global.check.username"/></div>
</c:if>
<c:if test="${checkusername == 'username.length'}">
   div class="loi"><s:message code="global.check.usernamelength"/></div>
</c:if>

<c:set var="checkusername"><form:errors path="username"/></c:set>
<c:if test="${checkusername eq 'username.id'}">
   div class="loi"><s:message code="global.check.username"/></div>
</c:if>
<c:if test="${checkusername eq 'username.length'}">
   div class="loi"><s:message code="global.check.usernamelength"/></div>
</c:if>

比较的结果,预示为假,因此无法按预期工作如果我将其测试为<c:if test="${not empty checkusername}">,它确实可以工作,但是由于我也想检查它的长度,因此它对我没有帮助。

这是我的属性代码:

global_vi.properties

global.check.username=Không được để username trống
global.check.usernamelength=username nhiều nhất là 50 chữ

global.properties

global.check.username=Do not leave username empty
global.check.usernamelength=Username only contain 50 words

我的模特用户:

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

    @Id
    @Column(name = "username")
    @NotBlank(message = "username.id")
    @Size(min=0,max=50,message="username.length")
    private String username;

    @Column(name = "password")
    @NotBlank(message = "Không được để trống mật khẩu")
    private String password;

    @Column(name = "fullname")
    @NotBlank(message = "Không được để trống họ tên")
    private String fullname;

    public User() {

    }

    public User(String username, String password) {
        this.username = username;
        this.password = password;
    }

    public User(String username, String password, String fullname) {
        this.username = username;
        this.password = password;
        this.fullname = fullname;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getFullname() {
        return fullname;
    }

    public void setFullname(String fullname) {
        this.fullname = fullname;
    }
java spring jstl el
1个回答
0
投票

您可以使用bean验证显示多语言环境错误消息。

© www.soinside.com 2019 - 2024. All rights reserved.