In table definition, it is often defined by snake case (\ _ delimited). For example, an example of a master that stores user information will be described. Table name: mst \ _user
Logical name | Physical name |
---|---|
User ID | user_id |
username | user_name |
Application development languages are often not snake cases. For example, in the case of java, it may be Pascal case and Camel case.
Taking java as an example, the class (DTO) corresponding to mst_user is as follows according to the Java convention (Pascal case, camel case).
public class MstUser {
private String userId;
private String userName;
// getter,setter omitted
}
Although the table is a snake case, mapping is required because the java convention is different. There are some problems associated with this.
The burden of creating specifications is heavy Example) Wrong when creating API specifications. Since there are usually many items, it is easy to make a mistake by copying the items from the table definition and replacing the snake case with camel case. user_id => userid => I made a mistake! In particular, when only designing and requesting development to the outside, a Q & A such as "What about userId?"
It is troublesome if you make a mapping mistake during development Since SQL is a snake case, it is necessary to describe the mapping to java class. If it can be automatically generated by the OR mapper, if it is a specification that joins, the mapping will be written steadily, so there is a possibility of making a mistake. The value acquisition result is null => It happens that there was a mapping error.
Mutual conversion between snake case and camel case is troublesome Although it is related to 1 and 2, it takes a lot of time and effort to convert snake case => camel case and camel case => snake case when mapping. It may be a little better if you make a tool, but it is still a hassle.
Follow the java conventions.
Table name: MstUser
Logical name | Physical name |
---|---|
User ID | userId |
username | userName |
DTO
public class MstUser {
private String userId;
private String userName;
// getter,setter omitted
}
This will save you the trouble of mapping, so you can design and develop efficiently. Are there any disadvantages?
Recommended Posts