Rookie @ Java When I was reviewing the source code during the training, I was uncertain, so I looked it up.
** ・ ・ ・ There is no difference in appearance. ** ** Really, really. The contents are (almost) unchanged, only the usage is different. All three are just beans. Rookie: beginner: If you think that form, entity and dto are "bean nicknames that indicate how to use them", I think: ok: for the time being.
It's a class like this. There are various properties, and they have setter / getter methods for those properties.
MemberBean.java
public class MemberBean {
private String name;
private int age;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return this.age;
}
public void setAge(int age) {
this.age = age;
}
}
In the above: arrow_up: example, the class name is "MemberBean",
--For form: MemberForm --For entity: Member --For dto: MemberDto
I think that it often happens.
--Contains the value (= form tag content) sent by the HTTP POST method. ――So, I feel like I don't use it much except for web services. ――Because it is the contents of the form tag, you should remember that the name of the bean is also form. --The class name is often "xxxForm".
--Enter the value to be registered / updated in the DB. --Hold the value obtained from DB. --Class names and table names are often the same.
--The abbreviation for Data Transfer Object is dto. --As the name suggests, a bean for exchanging data. ――It's enough not to use it at the training level for newcomers ... Or is there often no need to use it?
Data exchange means, for example, conversion from form to entity. For example, in form, the input is divided into year / month / day, but if the date of birth is of Date type on the DB, it is necessary to combine at some timing. In this case, if you edit the form or entity directly, you may not be able to restore the original data if something happens. To avoid that, put it in dto once ...
** form, entity and dto are all Bean **, and they are only named because they have different purposes. Personally, I think it is difficult to find the significance of using three beans properly in a new employee training level program. However, when trying to create a large-scale system, I feel that the beans according to the purpose take control of the entire system (at the program level).
Recommended Posts