目前日期文章:202001 (21)

瀏覽方式: 標題列表 簡短摘要

這篇主要是提供成田機場往來東京23區的交通方式,用來做訂房時區域的參考特別有用,直接先奉上懶人包 ( 我自己找飯店會先參考的站點 )

 懶人包:住宿建議車站 

連接機場:成田機場

  • 京成電鐵:日暮里站、上野站、押上站
  • 都営浅草線:浅草站、浅草橋站、東日本橋站、日本橋站、新橋站
  • JR:東京站、品川站、新宿站、新橋站
  • BUS:東京站、新宿站、品川站

PS.1 住宿比較便宜的地方:日暮里站、浅草站、浅草橋站、東日本橋站
PS.2 其實我覺得品川到市區有點遠,如果只在東京市區的話,品川不是那麼推薦

image

先來看看下面這張圖,可以發現東京交通有夠亂!我去了那麼多次其實還是搞不清楚那條線怎麼跑(雖然現在google map很方便沒錯啦.....),不過也透過寫這篇文讓我認真研究一下東京的交通了

文章標籤

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

try catch use:

if(e instanceof RestClientException && e.getCause() instanceof HttpMessageNotReadableException) {
        //TODO
 }

org.springframework.web.client.RestClientException: Error while extracting response for type [class com.test.res] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: (PushbackInputStream); line: 1, column: 2]

文章標籤

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

解壓縮的時候發現

net.lingala.zip4j.ZipFile.isEncrypted() throws net.lingala.zip4j.exception.ZipException: Expected central directory entry not found (#1)

一路追發現主要是出錯在 at net.lingala.zip4j.headers.HeaderReader.readCentralDirectory(HeaderReader.java:168)
主要為檔案有異常

然後看到「ZIP4j 压缩与解压」https://blog.csdn.net/u011165335/article/details/50496930
這篇有提到

在添加文件时,发现只能添加一次,再次添加报错:Expected central directory entry not found (#1),

 

文章標籤

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

@JsonFormat

  • 物件<->JSON 格式化互轉
  • 格式前端到後端、格式後端到前端
  • 資料交換如果以JSON交換,用此就可以了

@DateTimeFormat

  • spring mvc 格式前端到後端資料
  • 適用在form mapping

 

JSON傳值

{"testTimeA": "2020/08/26 18:42:12"}

後台設定物件

@lombok.Data
@ApiModel
public class testReq {

  @ApiModelProperty
  @JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", shape = JsonFormat.Shape.STRING, timezone = "GMT+8")
  private Date testTime;
}

==> 
back-end value:  testTime=Wed Aug 26 18:42:12 CST 2020

文章標籤

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

table 複合主鍵 同時使用 JAXB annotation設定

  • 主pojo set @Id@IdClass(xxx.class)、並設定@XmlElement
/**
 *主檔
 */
@Entity
@lombok.Data
@lombok.ToString
@Table(name="STORE_INFO")
@XmlAccessorType(XmlAccessType.FIELD)
@IdClass(StoreInfoPK.class)
public class StoreInfo implements Serializable {

  private static final long serialVersionUID = 1L;
  
  @Id
  @XmlElement(name = "StoreId")
  private String storeId;
  
  @Id
  @XmlElement(name = "CreateTime")
  private Date createTime;

  /**
   * 店鋪店名
   */
  @XmlElement(name = "StoreName")
  @Column(name = "STORE_NAME")
  private String storeName;

  public SupStoreInfo() {}

}

table 複合主鍵 並用 JAXB annotation設定

  • PK pojo set @Column
/**
 *PK
 */

@lombok.Data
@lombok.ToString
public class StoreInfoPK implements Serializable {

  private static final long serialVersionUID = 1L;

    @Column(name="STORE_ID")
    private String storeId;

    @Column(name="CREATE_TIME")
    @Temporal(TemporalType.DATE)
    private Date createTime;
    
    public StoreInfoPK() {
    }
}

文章標籤

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

 @Test
 public void tryremove() throws Exception {
    List<String> list = new ArrayList<String>();
    list.add("9");list.add("888");list.add("846");list.add("654");list.add("844");
    System.out.println("list: " + StringUtils.join(list, ","));
    
    if(CollectionUtils.isNotEmpty(list)){
      Iterator<String> it = list.iterator();
      while(it.hasNext()){
        String temp = it.next();
        System.out.println(temp);
        
        if(temp.startsWith("84")) {
          it.remove();
        }
      }
      
      System.out.println("list: " + StringUtils.join(list, ","));
    }
  }

//console:
list: 9,888,846,654,844
9
888
846
654
844
list: 9,888,654

文章標籤

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

AMAZON S3

使用官方SDK進行資料交換,

先安裝必要資料

POM.XML

<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-s3 -->
<dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-s3</artifactId>
        <version>1.11.767</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-kms -->
<dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-kms</artifactId>
        <version>1.11.767</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-core -->
<dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-core</artifactId>
        <version>1.11.767</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/jmespath-java -->
<dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>jmespath-java</artifactId>
        <version>1.11.767</version>
</dependency>

上傳物件 

String access = "access"; //ex: AKIA3PGEPUAAAAAABBBB
String secret = "secret"; //ex: W3pIE45y64DAjeRXyBUQAAAAAAAAAABBBBBBBBBB
Regions regions = Regions.AP_EAST_1;
String bucket = "bucket";
String fileName = "test/data.jpg"; //檔案(包含資料夾)

//憑證
AWSCredentials creds = new BasicAWSCredentials(access, secret); 

//建立連線
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                .withRegion(regions)
                .withCredentials(new AWSStaticCredentialsProvider(creds))
                .build();

//資料設定
PutObjectRequest request = new PutObjectRequest(bucket, fileName, new File("C:\\Users\\aaa\\Desktop\\logo.jpg"));
//Metadata
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType("image/jpg");
request.setMetadata(metadata);
//ACL
//https://docs.aws.amazon.com/zh_tw/AmazonS3/latest/dev/acl-overview.html 
request.setCannedAcl(CannedAccessControlList.PublicRead);

//開始傳送
s3Client.putObject(request);

取得檔案路徑

String access = "access"; //ex: AKIA3PGEPUAAAAAABBBB
String secret = "secret"; //ex: W3pIE45y64DAjeRXyBUQAAAAAAAAAABBBBBBBBBB
Regions regions = Regions.AP_EAST_1;
String bucket = "bucket";
String fileName = "test/data.jpg"; //檔案(包含資料夾)

//憑證
AWSCredentials creds = new BasicAWSCredentials(access, secret); 

//建立連線
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                .withRegion(regions)
                .withCredentials(new AWSStaticCredentialsProvider(creds))
                .build();

//s3路徑
String fileUrl = s3Client.getUrl(bucket, fileName).toString();

取得物件 

文章標籤

咪卡恰比 發表在 痞客邦 留言(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) 人氣()

Returns an immutable collection containing only the specified object. The returned set is serializable.
/**
 * Set<T> java.util.Collections.singleton(T var0)
 * https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#singleton-T-
 */
Set<String> aa = Collections.singleton("AA");


/**
 * List<T> java.util.Collections.singletonList(T var0)
 * https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#singletonList-T-
 */
List<String> bb = Collections.singletonList("BB");


/**
 * Map<K, V> java.util.Collections.singletonMap(K var0, V var1)
 * https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#singletonMap-K-V-
 */
Map<String, String> cc = Collections.singletonMap("CCKey", "CCVal");

 

 

refer:

https://stackoverflow.com/questions/4801794/use-of-javas-collections-singletonlist
https://stackoverflow.com/questions/31599467/what-is-the-benefit-for-collections-singleton-to-return-a-set-instead-of-a-col
 


文章標籤

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

org.apache.commons.lang3.exception.ExceptionUtils.ExceptionUtils.getStackTrace(Throwable)

 

ref:  https://stackoverflow.com/questions/1149703/how-can-i-convert-a-stack-trace-to-a-string


文章標籤

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

import java.util.Random;  
public static void main(String[] args) {
    System.out.println(new Random().nextInt(90)+10); //86 (取10~99)
    System.out.println(new Random().nextInt(10));    //3  (取0~9)
    System.out.println(new Random().nextInt(9)+1);   //4  (取1~9)
    System.out.println(new Random().nextInt(2));     //1  (取0~9)
}

new Random().nextInt(n):取0~(n-1)之正整數

n需為正數

refer:  https://docs.oracle.com/javase/7/docs/api/java/util/Random.htm


文章標籤

咪卡恰比 發表在 痞客邦 留言(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) 人氣()

gson使用 @SerializedName

  @SerializedName("data")
  private String name;

 

jackson使用

  @JsonProperty("data")
  private String name;

 

REFER

https://www.javadoc.io/doc/com.google.code.gson/gson/2.6.2/com/google/gson/annotations/SerializedName.html

 

文章標籤

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

  1. 繼承變數同步印出
    增加callSuper設定@lombok.ToString(callSuper=true)
@lombok.Data
@lombok.ToString(callSuper=true)
public class addre extends member{
}
  1. 指定變數不印出
    增加exclude設定@lombok.ToString(exclude= {"status"})
@lombok.Data
@lombok.ToString(exclude= {"status"})
public class addre extends member{
  String status;
  String city;
}

文章標籤

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

AMAZON S3

使用官方SDK進行資料交換,

先安裝必要資料

 

POM.XML

<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-s3 -->
<dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-s3</artifactId>
        <version>1.11.767</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-kms -->
<dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-kms</artifactId>
        <version>1.11.767</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-core -->
<dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-core</artifactId>
        <version>1.11.767</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/jmespath-java -->
<dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>jmespath-java</artifactId>
        <version>1.11.767</version>
</dependency>

get Bucket ACL

String access = "access"; //ex: AKIA3PGEPUAAAAAABBBB
String secret = "secret"; //ex: W3pIE45y64DAjeRXyBUQAAAAAAAAAABBBBBBBBBB
Regions regions = Regions.AP_EAST_1;
String bucket = "bucket";

//憑證
AWSCredentials creds = new BasicAWSCredentials(access, secret); 

//建立連線
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                .withRegion(regions)
                .withCredentials(new AWSStaticCredentialsProvider(creds))
                .build();

AccessControlList aclRes = s3Client.getBucketAcl(bucket);

for (Grant grant : aclRes.getGrantsAsList()) {
        System.out.println(grant.getGrantee().getIdentifier()); //182168387c385e506634d27dd5284f
        System.out.println(grant.getPermission());              //FULL_CONTROL
}

get Bucket Version On or Off

文章標籤

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

序列和反序列設定,可以設定物件轉換模式

EX:

package com.bean.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;


@lombok.Data
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Response {

  @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
        String message;
  
  @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
        String code;

}

refer:  http://fasterxml.github.io/jackson-annotations/javadoc/2.6/com/fasterxml/jackson/annotation/JsonProperty.Access.html


文章標籤

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

HTTP基本認證(Basic access authentication):http reques建立時,將user name和password放入header進行認證。

  1. user傳送http request 給伺服器
  2. server返回401 Unauthozied,並在Response header 放入 Access Authentication(EX: WWW-Authenticate: Basic realm="target Realm")。觸發瀏覽器帳密表單彈出
  3. user輸入user name和password,瀏覽器用BASE64邊碼後將資料放在header  Authorization (EX:  Authorization: Basic asdqwetqqrrwqrwqrqw)
  4. server取得Authorization value,進行認證

優點:

  • 方便快捷

缺點:

  • user name和password容易被破解,建議在私有環境使用
  • 不關閉瀏覽器的情況下,並沒有一種有效的方法來讓用戶登出

 

refer: 

https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/WWW-Authenticate
https://carsonwah.github.io/http-authentication.html

文章標籤

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

HttpServletResponse.sendRedirect()

  • 使用相對地址會導到port80
  • 瀏覽器端工作,瀏覽器會出現重定向頁面的URL
  • url可帶參數

RequestDispatcher.forward()

  • 伺服器的內部機制
  • url不能帶參數 (可使用response.setAttribute)

refer:

https://ithelp.ithome.com.tw/articles/10185109


文章標籤

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

select orderId, count(case paid when 'N' then 1 end) from orderitem

 

use case to filter data

 

refer: https://stackoverflow.com/questions/1400078/is-it-possible-to-specify-condition-in-count


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

public static <T> List<T> copyPropertiesList(List<?> src, Class<T> clazz) {
        if (CollectionUtils.isNotEmpty(src)) {
          Gson gson = new GsonBuilder().serializeNulls().create();
                
          List<T> lst = new ArrayList<>();
          
          JsonArray array = JsonParser.parseString(gson.toJson(src)).getAsJsonArray();
          for (JsonElement elem : array) {
                  lst.add(new Gson().fromJson(elem, clazz));
          }
          return lst;
          
        }else{
          return null;
        }
}

文章標籤

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

1 2