SPRING JDBC / CATATAN</>↗Spring JDBC03 Jul 2026
You can use JDBC with Spring through Spring’s JDBC support, especially JdbcTemplate. It removes much of the repetitive JDBC boilerplate such as opening connections, closing resources, handling PreparedStatement, iterating ResultSet, and translating SQLException into Spring’s DataAccessException hierarchy. The typical setup is: Configure a DataSource Create a JdbcTemplate Inject it into a repository/DAO class Use it […]
SPRING DATA JPA / CATATAN</>↗Spring Data JPA03 Jul 2026
To connect Spring to a database, the usual modern approach is: Add database-related dependencies. Configure the database connection properties. Create an entity. Create a repository. Use the repository from a service or controller. The simplest way is with Spring Boot + Spring Data JPA. 1. Add Maven Dependencies For a Spring Boot application using JPA, […]
SPRING MVC / CATATAN</>↗Spring MVC03 Jul 2026
In Spring MVC, handle exceptions globally by creating a class annotated with @ControllerAdvice or @RestControllerAdvice and adding methods annotated with @ExceptionHandler. For REST APIs, prefer @RestControllerAdvice, because it combines @ControllerAdvice and @ResponseBody, so returned objects are serialized as JSON automatically. package com.example.demo.exception; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springfr...
SPRING MVC / CATATAN</>↗Spring MVC03 Jul 2026
In Spring MVC, the standard way to validate form data is to use Jakarta Bean Validation annotations on a form/DTO object, then check validation results in your controller with BindingResult. Since your project uses Jakarta EE, use jakarta.validation.* imports. 1. Add validation annotations to your form object Example form/DTO: import jakarta.validation.constraints.Email; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; […]
SPRING MVC / CATATAN</>↗Spring MVC03 Jul 2026
In Spring MVC or Spring Boot, you handle HTTP requests by creating controller classes. A controller receives a request, runs application logic, and returns either: a view name for server-rendered pages, or data such as JSON for REST APIs. 1. Basic Spring MVC Controller Use @Controller when you want to return views such as JSP, […]
SPRING MVC / CATATAN</>↗Spring MVC03 Jul 2026
Building a Web Application Using Spring MVC A Spring MVC web application is typically built around these pieces: DispatcherServlet — the front controller that receives HTTP requests. Spring MVC configuration — enables MVC and configures controllers, view resolution, static resources, etc. Controllers — handle web requests. Services — contain business logic. Repositories — handle persistence, […]