Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpEL动态消息的实现 #38

Open
liushigong opened this issue Oct 5, 2024 · 5 comments
Open

SpEL动态消息的实现 #38

liushigong opened this issue Oct 5, 2024 · 5 comments

Comments

@liushigong
Copy link

通过SpEL对注解中的message消息进行动态替换,适用于一些特殊数据校验提示的场景

@stick-i
Copy link
Owner

stick-i commented Oct 5, 2024

请补充几个具体的场景。

@liushigong
Copy link
Author

在Excel导入的数据中,经常校验数据的准确性,需要将不正确的数据在message提示出来

@stick-i
Copy link
Owner

stick-i commented Oct 8, 2024

请写详细一点,并提供一个具体的例子。关键是你期望的message是什么样的?

@liushigong
Copy link
Author

根据当前SpEL规则来定制,例如我们得提示是“上传失败,仓库编码:%s未匹配到仓库信息,请检查导入数据”,可以通过咱们组件中改成“上传失败,仓库编码:{#this.areaCode}未匹配到仓库信息,请检查导入数据”

@stick-i
Copy link
Owner

stick-i commented Oct 8, 2024

涉及业务信息的校验,一般建议在业务逻辑中抛出具体异常信息。

在你这个例子中,应该是需要通过调用 Spring Bean 的方式来查询仓库编码是否存在,这种情况下你可以直接在业务方法中抛出对应的异常进行处理。

参考文档:https://spel-validator.sticki.cn/guide/user-guide.html#%E5%A4%84%E7%90%86%E4%B8%9A%E5%8A%A1%E5%BC%82%E5%B8%B8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants