Tag Archives: The back-end

Mybatis idea environment integration jar package

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.47</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.3.4</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.3.4</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.8.13</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>2.0.2</version>
        </dependency>
    </dependencies>

Error reporting when Lombok @ data and @ builder are used together

Lombok @data and @builder are used together
Lombok often uses annotations

error
Sometimes @Builder annotation is added to PO class in order to make the code more elegant when constructing PO class. However, because @Builder and @Data will be used together, the class’s no-argument constructor will be overwritten. As a result, some framework can not successfully assign Data to PO class when operating the database, such as MyBatis.
The solution
Override the no-argument constructor in the class to prevent conflict with Lombok’s annotation, and add the @tolerate annotation on the no-argument constructor
Such as:

@Data
@Builder
public class DataBuilder implements Serializable {

    @Tolerate
    public DataBuilder (){}

}

Lombok uses annotations
A lot of online lecture Here I think a good link
https://www.cnblogs.com/heyonggang/p/8638374.html

com.alibaba.fastjson .JSONException: For input string: “3000-01-01” or “9999-12-31”

FastJSON Parser exception after 2999 time range

Exception in thread "main" com.alibaba.fastjson.JSONException: For input string: "9999-12-31 00:00:00.000+0000"
    at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:665)
    at com.alibaba.fastjson.JSON.parseObject(JSON.java:365)
    at com.alibaba.fastjson.JSON.parseObject(JSON.java:269)
    at com.alibaba.fastjson.JSON.parseObject(JSON.java:488)
    at com.xxx.xxx.main(StpBpmVariableSetter.java:146)
Caused by: java.lang.NumberFormatException: For input string: "9999-12-31 00:00:00.000+0000"

FastJSON is known to be fixed in version 1.2.49, and can be fixed with an upgrade

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.49</version>
</dependency>

 

Solve the problem that data cannot be input in idea console

IDEA console cannot be entered
If you are using IDEA and you find that you cannot input from the console while testing with JUnit, you need to make the following changes to make the configuration successful
Step 1: Help –Edit Constom VM Options…

Step 2: open the configuration, add – Deditable. Java. Test. The console = true

If the configuration is successful, restart IDEA and the problem will be solved

Mybatis error “field ‘ID’ doesn’t have a default value”

SelectKey = SelectKey; SelectKey = SelectKey; SelectKey = SelectKey; SelectKey = SelectKey; SelectKey = SelectKey; SelectKey = SelectKey; SelectKey = SelectKey

   @Insert({"insert into song(name,singer,category,writer,language,issudate)values(#{name},#{singer},#{category},#{writer},#{language},#{issudate})"
    })
    @SelectKey(statement = "select last_insert_id()",before = false, resultType = Integer.class,keyProperty = "id")
    public int insert(Songs songs);
}

Resttemplate Chinese garbled problem – available

RestTemplate Chinese garbled code problem
Source code to see the cause of Chinese code solution

Causes the RestTemplate to receive parameters in the request response body with scrambled Chinese characters.
Source code to see the Reason for Chinese scrambled code


to take a closer look at the initialization parameter in the figure above, the default value of this parameter is as shown in the figure below.

you should know the cause of this problem and the solution. [after the RestTemplate is initialized, we will assign and modify it to the utf-8 code we need]
The solution
The SpringBoot project takes the following approach

@Configuration
public class RestTemplateConfig {
    @Bean
    public RestTemplate restTemplate(){
        RestTemplate restTemplate = new RestTemplate(factory);
        restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
        return restTemplate;
    }
  }

spring boot Whitelabel Error Page

Appears when spring Boot is running
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sat Feb 16 00:12:17 CST 2019
There was an unexpected error (type=Not Found, status=404).
No message available
Here’s my solution
The Application startup class is not in the right place. To place the Application class on the outermost side, it contains all subpackages
reason :spring-boot automatically loads all components under the package where the startup class is located and under its subpackages.

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request p

in the course of using springboot today, Met the Servlet service () for the Servlet [dispatcherServlet] in context with the path [] threw the exception [Request processing failed; nested exception is Java. Lang. NullPointerException] with root cause error, really sad, Write it down.
error reason:
I cited in the service implementation class two resource bundle files, but only write a @ Autowared, so only the first package is automatically injected, and the second package is not injection, So, should be to write a @ Autowared
so my problem is solved!