目前分類:java_spring (10)

瀏覽方式: 標題列表 簡短摘要
SpringBoot Admin可用來監控SpringBoot服務,安裝簡單, 紀錄一下實作過程: 

要起兩台服務,監控server 和 目標client 

監控server:

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

spring data jpa error

org.hibernate.QueryException: Named parameter not bound : __$synthetic$__25

 

處理方式:
spring-data-commons升版


官方ISSUE:
Avoid potentially expensive constructor parameter creation where possible

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

使用JsonProperty 定名

@JsonProperty("uid")
@ApiModelProperty(required=true, example="13690000")
private String memberId;

/* swagger-ui
{
    "uid": 13690000,
}
*/

refer:  https://github.com/springfox/springfox/issues/1289


文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

spring使用JdbcTemplate進行OR mapping的時候,對應column名稱支援底線_
主要是下面這段程式

       /**
         * Initialize the mapping meta-data for the given class.
         * @param mappedClass the mapped class
         */
        protected void initialize(Class<T> mappedClass) {
                this.mappedClass = mappedClass;
                this.mappedFields = new HashMap<>();
                this.mappedProperties = new HashSet<>();
                PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(mappedClass);
                for (PropertyDescriptor pd : pds) {
                        if (pd.getWriteMethod() != null) {
                                this.mappedFields.put(lowerCaseName(pd.getName()), pd);
                                String underscoredName = underscoreName(pd.getName());
                                if (!lowerCaseName(pd.getName()).equals(underscoredName)) {
                                        this.mappedFields.put(underscoredName, pd);
                                }
                                this.mappedProperties.add(pd.getName());
                        }
                }
        }

例如:

public class CardInfo {
  private String name;
  private String expirationYear;
  private String expirationMonth;
}

經過處理mapping對象為以下

mappedFields={
expiration_year=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=expirationYear],
expirationyear=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=expirationYear],
expiration_month=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=expirationMonth],
expirationmonth=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=expirationMonth],
name=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=name]
}
mappedProperties=[expirationYear, name, expirationMonth]

 

 

 

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

主要透過SQL COALESCE做資料處理判斷,COALESCE ( expression [ ,...n ] )傳回第一個非null expression

JPA運作:

----------

List<Long> testList= new ArrayList();
testList.add(null);
testList.add(Long.valueOf(13699885));

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

spring boot cache 結合 redis 快取機制設定
使用spring boot版本:2.1.6

  1. pom.xml
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-mail</artifactId>
</dependency>

 

  1. application.yml
    增加快取管理設定
    reference:
    Redis Sentinel Support https://docs.spring.io/spring-data/data-redis/docs/current/reference/html/#redis:sentinel
spring:
  cache:
    type: REDIS
  redis:
    jedis:
      pool:
        max-idle: 8
        min-idle: 0
        max-active: 8
        max-wait: -1
    sentinel:
      master: mymaster
      nodes: 127.0.0.1:26379

 

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

比對相同資料寫法

有一筆pojo資料,要查出與他相同的其他資料

 POJO 

@Entity
@Table(name = "RECEIVER")
public class ReceiverDTO implements Serializable {

  private static final long serialVersionUID = -5368343800218280407L;

  @Id
  private String id;

  @Column
  private String name;

  @Column
  private String email;

  @Column
  private String mobile;

  @Column
  private String phone;

 @Temporal(TemporalType.TIMESTAMP)
 @Column
 private Date updateTime;

  public MemReceiverDTO() {
    super();
  }

  public String getId() {
    return id;
  }

  public void setId(String id) {
    this.id = id;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
      this.name = name;
  }

  public String getEmail() {
    return email;
  }

  public void setEmail(String email) {
    this.email = email;
  }

  public String getMobile() {
    return mobile;
  }

  public void setMobile(String mobile) {
    this.mobile = mobile;
  }

  public String getPhone() {
    return phone;
  }

  public void setPhone(String phone) {
    this.phone = phone;
  }

  public Date getUpdateTime() {
    return updateTime;
  }

  public void setUpdateTime(Date updateTime) {
    this.updateTime = updateTime;
  }

}

 

 hibernate 

  public List<ReceiverDTO> findSameData(ReceiverDTO DTO) {
    //搜尋資料以Map包裝
    Map map = new HashMap();
    map.put("name",DTO.getName());
    map.put("mobile",DTO.getMobile());
    map.put("email",DTO.getEmail());

    Criteria criteria = this.getSession().createCriteria(ReceiverDTO.class);
    criteria.add(Restrictions.allEq(map));  //下條件
    criteria.addOrder(Order.desc("updateTime"));

    return criteria.list();
  }

 

 Spring Data JPA 

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

springdata jpa使用Example快速实现动态查询
https://blog.csdn.net/long476964/article/details/79677526

Spring Data JPA ——默认方法使用
https://segmentfault.com/a/1190000011067941


文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

service需先進行delect 再select新資料

service:

@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  public List<CreditCardInfoResponse> getCreditCardList(Long fridayUid) {
      //移除資料
      prodDao.deleteByProdId(prodId);
      prodDao.flush();
      
      //撈取資料
      List<prod> prodList = prodDao.findByProdId(ProdId);
  }

Dao

  public interface prodDao{
  
        public List<prod> findByProdId(Long prodId);
        
        @Modifying
        @Transactional
        @Query("delete from Prod where prodId = :prodId")
        public int deleteByIdFridayUidAndIsDefault(Long prodId);
  }

==>

如果表定Query,實際對資料庫操作

1.  delete from PROD  where PRODID=?

2.  select PRODID, PRODNAME from PROD  where PRODID=?

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

要驗證的資料加上@Validated注解,表示spring必須對其進行檢核,BindingResult 則存放檢核後的訊息  (此兩值需相鄰)。

public ResultView quoteValidate(@Validated DataVO dataVO , BindingResult resul) {

}

 

多個資料需要檢核的話,則一對一對設定 ->

(@Validated DataOneVO dataOneVO , BindingResult resul ,@Validated DataTwoVO dataTwoVO , BindingResult resul);

 

 

 


文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()