feat: 添加数据库支持,保存测算记录
- 添加Spring Data JPA和H2/MySQL数据库依赖 - 创建DeductRecord实体类,保存测算记录 - 创建DeductRecordRepository和DeductRecordService - 创建RecordController,提供记录查询和删除API - 修改BaZiController,保存测算结果到数据库 - 配置H2数据库用于开发,MySQL用于生产环境
This commit is contained in:
1 parent
251a49d810
commit
683f55e4ca
7 files changed
+338
No files matched your search
@@ -0,0 +1,20 @@
|
||||
package xuan.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import xuan.entity.DeductRecord;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface DeductRecordRepository extends JpaRepository<DeductRecord, Long> {
|
||||
|
||||
List<DeductRecord> findByUserIdOrderByCreateTimeDesc(String userId);
|
||||
|
||||
List<DeductRecord> findByUserIdAndTypeOrderByCreateTimeDesc(String userId, String type);
|
||||
|
||||
@Query("SELECT d FROM DeductRecord d WHERE d.userId = :userId ORDER BY d.createTime DESC LIMIT 10")
|
||||
List<DeductRecord> findTop10ByUserIdOrderByCreateTimeDesc(@Param("userId") String userId);
|
||||
}
|
||||
Reference in new issue
Block a user