English 中文(简体)
什么是制约验证点?
原标题:What is point of constraint validation @Null?
最佳回答
问题回答

@Null是一个非常重要的说明。 这并非毫无用处。 请允许我展示一个共同使用案例。 Say,有Id汽车产生的DAO(准号)物体。

If you use separate classes for DTO and DAO, @GetMapping returns list of DTOs without issues. On the other hand, @PostMapping for adding a new element requires that input DTO must not contain Id field and even if present it must be null or undefined. Such an input when converted to and from DTO object, expects Id must be blank. For this, @Null is the only choice

@PutMapping expects id must not be blank so @NotNull is required for id field when we expect update happens to a single object.

@DeleteMapping, 只有我们希望删除一个已知的Id的物体时,才要求进行简单的分类。

还有一些其他复杂案件,通常不处理,但具有意义。

@GetMapping可用于任何已提供领域,但若提供Id以外的任何领域,Id必须空白。 如果提供Id,那么所有其他人都必须是空白。

There is also a complicated @PutMapping requirement, where in partial information is provided for update and expected remaining fields to be older values. Here non-null fields are updated.

删除或删除另一个注释:@DeleteMapping。 如果将其计算成空白,则可以采用@Null限制。

通常的CRUD业务过于简单,但不适合实际预期。

All these mix of requirements can be listed into groups. And constraints can be provided with groups attribute with separate Marked interface @Validated can be applied as per requirement.





相关问题
Recommended way to develop using Jetty and Eclipse

I am currently developing a J2EE application and I would like to use Jetty. I would like to have iot integrated with Eclipse, so I could debug the appliaction. I ve tried out couple of plugins (...

Call function periodically in Java

we need run one function periodically in Java web application . How to call function of some class periodically ? Is there any way that call function when some event occured like high load in server ...

Why make an EJB rather than a Web Service?

I would have thought that there is a lot of information out there on this, but I haven t found anything that really answers my question. What are the advantages of making an EJB rather than a web ...

Where should I put this configuration setting?

I m designing a fairly small web application which will run on a Sun application server (v9.1). It only has a few pages, no database of its own, and will retrieve/update data via web services. There s ...

JNDI Names -- Is Prefix "jdbc/" needed?

What s up with JNDI names? I m trying to get a javax.sql.DataSource using the new annotations feature of Java 5. It s not working for me, so I want to ask... I have a in my web.xml, inside of it is ...

hibernate interceptors : afterTransactionCompletion

I wrote a Hibernate interceptor : public class MyInterceptor extends EmptyInterceptor { private boolean isCanal=false; public boolean onSave(Object entity, Serializable arg1, Object[] arg2, String[]...

热门标签