Spring-boot读书笔记一POJO class
POJO Definition
POJO = Plain Old Java Object
A POJO is a simple Java class with no special restrictions, following basic conventions:
// Simple POJO example
public class User {
private String name;
private int age;
// Default constructor
public User() {}
// Constructor with parameters
public User(String name, int age) {
this.name = name;
this.age = age;
}
// Getters and setters
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public int getAge() { return age; }
public void setAge(int age) { this.age = age; }
}
POJO Requirements
- No inheritance restrictions - doesn't extend framework-specific classes
- No interface requirements - doesn't implement framework interfaces
- No annotations required - works without special annotations
- Serializable - can be easily serialized/deserialized
- Default constructor - typically has a no-arg constructor
POJO vs Normal Class
|POJO |Regular Class
|Simple data container |Can have complex business logic
|Follows JavaBean conventions |No specific conventions
|Framework-agnostic |May depend on frameworks
|Easy serialization |May have serialization issues
|Minimal dependencies |Can have many dependencies
Special Effects of POJOs
1,Framework Compatibility: Works seamlessly with:
- JSON/XML serialization (Jackson, GSON)
- ORM frameworks (Hibernate, JPA)
- Spring Framework binding
- Reflection-based tools
2,Your AppProperties Example: While it has Spring annotations, the underlying structure follows POJO principles - simple fields, getters, and constructor.
Data Transfer: Perfect for:
- API responses/requests
- Database entity mapping
- Configuration binding
- Inter-service communication
POJOs provide simplicity, portability, and framework independence, making them ideal for data representation and transfer scenarios.

浙公网安备 33010602011771号