java - 公开 JSP 文件中未使用的属性 (Spring)

标签 java spring jsp

我们最近了解了 DTO(数据传输对象)以及为什么我们应该使用它们而不是直接来自数据库的对象。

我们的类名为Product,其中包含:id、code、price、name、description。 在 View 中,我们仅显示代码、价格、名称和说明,因此id未使用。 我们的培训师告诉我们,如果 id 会丢失,我们应该使用 DTO。否则,她告诉我们她可以在 View 中公开 id

这样的事情怎么可能呢?我们使用 .jsp 文件,这些文件在服务器端编译,转换为 .html 并发送给用户。你怎么可能公开一个不使用的字段?

最佳答案

Data Transfer Object that communicate with the database, In the database you probably store only the properties like in your example, id,code,price,name,description.

DTO 是一个简单的 POJO 类,具有 getter/setter 方法

您可以从 DTO 的 getter/setter 访问数据库,并且该属性很可能是私有(private)的。

The id is uniquly identified the products in your table and no need to show or expose from your presentation .jsp.

关于java - 公开 JSP 文件中未使用的属性 (Spring),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45198502/

相关文章:

java - 如何使用java api合并两个具有图表和表格的pptx文件?

java - 电子邮件地址错误

spring - 如何将 StatelessSession 与 Spring Data JPA 和 Hibernate 一起使用?

java - 使用 Office 2007/2010 打开 .xls 文件时收到扩展检查(强化)警报

java - jsp中的XSS攻击

java - 找不到符号且函数无法应用: Java

java - Libgdx 播放/暂停音乐

java - Spring MVC - 多部分表单数据

Spring 中的 Java Spring hibernate 和 JPA

java - JSP 重定向和传值