Files
springboot-demo/src/main/java/com/example/demo/model/UserEvent.java
likingcode 539dc41868 feat: Spring Boot示例项目
- 基础Spring Boot配置
- Docker支持
2026-03-07 05:43:15 +00:00

51 lines
1.5 KiB
Java

package com.example.demo.model;
import java.time.LocalDateTime;
/**
* 用户事件 - 演示 Spring 事件机制
*
* 学习点:
* - ApplicationEvent 基类
* - 事件驱动架构
* - 观察者模式
*/
public class UserEvent {
public enum Type {
CREATED, // 用户创建
UPDATED, // 用户更新
DELETED, // 用户删除
LOGIN // 用户登录
}
private Type type;
private Long userId;
private String userName;
private LocalDateTime timestamp;
private String detail;
public UserEvent() {
this.timestamp = LocalDateTime.now();
}
public UserEvent(Type type, Long userId, String userName, String detail) {
this.type = type;
this.userId = userId;
this.userName = userName;
this.detail = detail;
this.timestamp = LocalDateTime.now();
}
// Getters and Setters
public Type getType() { return type; }
public void setType(Type type) { this.type = type; }
public Long getUserId() { return userId; }
public void setUserId(Long userId) { this.userId = userId; }
public String getUserName() { return userName; }
public void setUserName(String userName) { this.userName = userName; }
public LocalDateTime getTimestamp() { return timestamp; }
public void setTimestamp(LocalDateTime timestamp) { this.timestamp = timestamp; }
public String getDetail() { return detail; }
public void setDetail(String detail) { this.detail = detail; }
}