赞
踩
@Data @Table(name = "task_apply") @Entity public class TaskApply { @Id @GeneratedValue @Column(name = "apply_id") private Long applyId; private Integer status; private SyncType type; @Column(name = "task_message") private String taskMessage; }
package com.charles.enums public enum SyncType { /** * 手动同步 */ MANUAL("M", "手动同步"), /** * 任务同步 */ SCHEDULED("S", "任务同步"); private final String value; private final String text; SyncType(String value, String text) { this.value = value; this.text = text; } public String text() { return text; } public String getValue() { return value; } public static SyncType fromValue(String type) { for (SyncType value : SyncType.values()) { if (value.equals(type)) { return value; } } return null; } }
import javax.persistence.AttributeConverter; public class SyncTypeConverter implements AttributeConverter<SyncType, String> { @Override public String convertToDatabaseColumn(SyncType e) { if (e == null) { return null; } return e.getValue(); } @Override public SyncType convertToEntityAttribute(String value) { if (value == null) { return null; } return SyncType.fromValue(value); } }
@Modifying
@Query("update TaskApply set status = :status where applyId = :applyId")
void updateStatusByApplyId(@Param("applyId") Long applyId, @Param("status") Integer status);
@Modifying
@Query("update TaskApply set status = ?2 where applyId = ?1")
void updateStatusByApplyId(Long applyId, Integer status);
package com.charles.vo;
@Data
public class TaskMessageVO {
private Long applyId;
private String taskMessage;
}
@Query("select new com.charles.vo.TaskMessageVO(applyId, taskMessage) from TaskApply where applyId in (:applyIds)")
List<TaskMessageVO> findTaskMessages(@Param("applyIds") List<Long> applyIds);
@Query(nativeQuery = true, value =
"SELECT id as applyId, task_message as taskMessage FROM task_apply WHERE apply_id IN (:applyIds)")
List<Object> findTaskMessages(@Param("applyIds") List<Long> applyIds);
这种写法是nativeQuery,返回的结果中每个Object中返回的是一个数组,数组下标0对应的是applyId,下标1对应的是taskMessage。
@Query("select distinct status from TaskApply where applyId in (:applyIds)")
List<Integer> findDistinctStatus(@Param("applyIds") List<Long> applyIds);
@Query("select applyId from TaskApply where type <> com.charles.enums.SyncType.MANUAL")
List<Long> findNotManualSyncApplyIds();
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。