Service
Object objectData = ObjectDTO.toEntity(objectDTO);
for(ObjectDetail one : objectData.getObject()){
objectRepository.save(one);
}
@Query(value = ""
+" SELECT count(A.newCnt) "
+" FROM (SELECT table.makeDate AS newCnt "
+" FROM data.Table table "
+" WHERE table.makeDate >= DATE_ADD(NOW(), INTERVAL -1 HOUR) "
+" ) A "
+" " , nativeQuery = true)
public Long countObject();
Entity
@Entity
@Getter
@Builder
@DynamicUpdate
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "TABLE_NAME")
public class Entity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "SEQ")
private int id;
@Column(name = "REG_DT")
private LocalDateTime regDate;
@Column(name = "USER_ID")
private String userId;
public void setUserId(String userId) {this.userId = userId;}
}
Repository
public interface ObjectRepository extends JpaRepository<Entity, Long>, ObjecRepositoryCustom {
public Page<Object> findByCategory(Pageable pageable, Category category);
}
Repository-QueryDSL Interface
public interface EntityRepositoryCustom {
public void updateEntity(EntityDTO entityDTO);
public int deleteById(Long id);
}
QueryDSL
public class ObjectRepositoryImpl extends QuerydslRepositorySupport implements ObjectRepositoryCustom {
public ObjectRepositoryImpl() { super(Entity.class); }
@Override
@Transactional
public void updateEntity(EntityDTO entityDTO) {
update(entity)
.where(
entity.id.eq(entityDTO.getId())
)
.set(entity.title, entityDTO.getTitle())
.execute();
}
@Override
public int deleteById(Long id) {
Long return = delete(category).where(category.id.eq(id)).execute();
return return.intValue();
}
}