The first time you use a Java development project, the techniques involved are DUBBO+SPRINGMVC+ZOOKEEPER+KAFKA+MONGODB.
The first task is to design a product log storage and Query service interface, the logical implementation is DUBBO+SPRINGMVC, the data is stored in MongoDB, zookeeper as a service intermediary. Because the usage frequency is not very high Kafka Message Queuing is not used.
Caller is used. NET write management background, the first tune-up found that there is a problem, some data values are not accepted, from the Controller came in is null value.
Some of the field values are not received, look for the Java group colleague, said my field naming does not conform to the Java specification, as for the reasons for not receiving is unclear.
I redesigned a new class in accordance with the Java naming convention, re-testing the problem all resolved, it seems that according to the specification can avoid a lot of pits.
The following is the solution of the Netizen
1. Correct method of handling:
Specify an alias for each property, and the method specified is similar to the controller, as follows:
public class User {
@JsonProperty (value = "Name") private String Name; @JsonProperty (value = ' age ') private int age;}
After specifying the appropriate name, the problem I encountered was resolved.
2. Analyze why the error occurred:
Because of the injection, using SetName (...), Setsex (...), according to the Java naming convention, the corresponding variable, name and sex will be assigned, but if the variable is named name and sex, the generated setter function is still setname ( ...), Setsex (...),
However, when the spring framework is injected, it will not be able to tell whether it is name or names, and still follow the naming rules, so the name is still assigned, and if it is not followed by a naming convention, it cannot be injected with name.
3. Conclusion:
Writing Java in the absence of other reasons, the most still in accordance with the Java programming specifications, after all, is a set of rules,
Everyone in accordance with this rule in doing things, if not according to the common sense of the card, then the problem is inevitable, out of this problem solved is also quite troublesome, after all, spring framework is not anyone can change.
Finally, the difference between C # and the attribute naming conventions in Java:
C # Shorthand public string ProductTitle {get; set;} According to the big Hump naming method, the first letter is generally required to capitalize
C # Full private string title= ""; Private variables
public string ProductTitle// serialized as JSON with this as the subject
{
Get{return This.title;}
Set{this.title=value;}
}
Java private String producttitle;//According to the small hump nomenclature, this is the property rather than the private variable in C #, which is the same as when serializing to JSON
Public String Getproducttitle()
{
return title;
}
public void Setproducttitle(String value)
{
title = value;
}
Null object value received in spring using @requestbody