Giải quyết các sự cố thường gặp trong phát triển Java

  1. Chênh lệch múi giờ 14 giờ giữa giao diện và cơ sở dữ liệu

    Thêm tham số múi giờ vào chuỗi kết nối JDBC:

    jdbc:mysql://localhost:3306/ten_database?useTimezone=true&serverTimezone=GMT%2B8
  2. PageHelper không hoạt động

    Cập nhật dependency trong pom.xml:

    <dependency>
        <groupId>com.github.pagehelper</groupId>
        <artifactId>pagehelper-spring-boot-starter</artifactId>
        <version>1.2.5</version>
    </dependency>
  3. IDEA không tự động làm mới HTML

    Cấu hình trong IntelliJ IDEA:

    • File → Settings → Build, Execution, Deployment → Compiler → Enable "Build project automatically"
    • Nhấn Ctrl+Shift+Alt+/ → Chọn Registry → Kích hoạt "compiler.automake.allow.when.app.running"
  4. Lỗi gạch chân đỏ trong Maven Dependencies

    Thực hiện tuần tự:

    1. Maven clean
    2. Cắt dependency từ pom.xml → Lưu
    3. Maven clean lần nữa
    4. Dán dependency lại → Lưu
  5. DataSource không tải driver cơ sở dữ liệu

    Sao chép thủ công vào thư mục cấu hình:

    C:\Users\tai_khoan\.IntelliJIdea2019.2\config\jdbc-drivers\MySQL Connector\J 8\8.0.15

    Yêu cầu 2 file: mysql-connector-java-8.0.15.jar và mysql-connector-license.txt

  6. Toàn bộ phương thức Test thất bại do lỗi biên dịch

    Kiểm tra lỗi cú pháp và cấu trúc mã nguồn trước khi chạy kiểm thử

  7. Cảnh báo trùng lặp mapper trong MyBatis

    Log cảnh báo:

    Skipping MapperFactoryBean - Bean already defined with the same name!
    No MyBatis mapper was found in package

    Giải pháp: Đảm bảo mỗi gói mapper chỉ được quét một lần

  8. Lỗi "Invalid bound statement" trong MyBatis

    Bổ sung cấu hình tài nguyên trong pom.xml:

    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </resource>
    </resources>
  9. Hiển thị câu lệnh SQL MyBatis

    Thêm cấu hình trong application.yml:

    mybatis:
      configuration:
        log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  10. Xung đột bean trong Spring Boot

    Kích hoạt ghi đè bean trong application.yml:

    spring:
      main:
        allow-bean-definition-overriding: true

Thẻ: mysql PageHelper IntelliJ_IDEA Maven mybatis

Đăng vào ngày 26 tháng 6 lúc 22:05