Java Problems Summary
Maven Related Problems
Solving Maven Remote Repository Jar Download Failures
Go to Maven Repository to find the corresponding dependency and download it.
Go to the download directory and execute the following command, replacing -DgroupId, -DartifactId, -Dversion, -Dfile
mvn install:install-file -DgroupId=io.confluent -DartifactId=kafka-schema-registry-client -Dversion=4.1.0 -Dpackaging=jar -Dfile=kafka-schema-registry-client-4.1.0.jar
mvnw clean occurs Some Enforcer rules have failed
Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce
(enforce-versions) on project SIMI: Some Enforcer rules have failed. Look above for
specific messages explaining why the rule failed. -> [Help 1]
not solved! stackoverflow website
To skip enforcer (not always working)
mvn clean install -Denforcer.skip=true
To continue the build if error
mvn clean install -Denforcer.fail=false
./mvnw clean install -DskipDistribution=true -Denforcer.skip=true
MyBatis Related Problems
UncategorizedSQLException when SQL query null value is mapped to int type
Change BO property from int to Integer type
org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation;
uncategorized SQLException for SQL []; SQL state [null]; error code [0];
Mysql tinyint is toxic
mysql do not use field type tinyint, possibly your update of 1 will become 49
MybatisPlus Invalid bound statement (not found) exception
IDEA Usage Related Problems
idea terminal Chinese garbled characters
# solve idea terminal Chinese garbled
export LANG="zh_CN.UTF-8"
export LC_ALL="zh_CN.UTF-8"
Other Problems
Dynamic Data Source Problems
If the operation used has a transaction, you need to set the data source before the Dao layer. In Dao or Mybatis-plus, service with dao will switch data source invalidly.
jackson serialization problems
LocalDateTime not supported by default
Java 8 date/time type java.time.LocalDateTime not supported by default:
add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable
handling (through reference chain: java.util.ArrayList[0]->xxx.xxx.xxx.xxx.XxxxPo["updatetime"])
First troubleshoot where it is reported
- If Spring Boot can be extended: directly extend
ObjectMapper
@Configuration
public class JacksonConfig implements WebMvcConfigurer {
@Override
public void extendMessageConverters(final List<HttpMessageConverter<?>> converters) {
MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
objectMapper.registerModule(new JavaTimeModule());
messageConverter.setObjectMapper(objectMapper);
converters.add(0, messageConverter);
}
}
- If cannot extend, consider skipping
Beanserialization step, such as using method to convert Bean to Map - If really no way, use
FastjsonorGjsoninstead
Second field uppercase problem
- Use
@JsonProperty
@JsonProperty is used to explicitly tell Jackson:
"This field (or method, constructor parameter) is to be used as a JSON property, and the property name is XXX."
- Use
@JsonAutoDetect
@JsonAutoDetect(
fieldVisibility = JsonAutoDetect.Visibility.ANY,
getterVisibility = JsonAutoDetect.Visibility.NONE,
setterVisibility = JsonAutoDetect.Visibility.NONE)
Members used in serialization and deserialization
| Usage Location | Influence Direction | Common Usage |
|---|---|---|
| Field | Serialization + Deserialization | Force include private fields |
| getter | Serialization | Change output field name |
| setter | Deserialization | Change input field name |
| Constructor Parameter | Deserialization | Map JSON parameter name to constructor parameter |
| record Parameter | Serialization + Deserialization | Control JSON property name |
Database Connection Pool Configuration Problems
When using Druid connection pool, config parameter validationInterval must be less than timeBetweenEvictionRunMillis, ensuring database connection is always available.
API Interface Standards
- Query data volume
- Input parameter check
- Response message large integer, floating point fields use string type
- Input parameter type not primitive type
- Attribution: Retain the original author's signature and code source information in the original and derivative code.
- Preserve License: Retain the Apache 2.0 license file in the original and derivative code.
- Attribution: Give appropriate credit, provide a link to the license, and indicate if changes were made.
- NonCommercial: You may not use the material for commercial purposes. For commercial use, please contact the author.
- ShareAlike: If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.