springboot學習筆記 json處理

2021-09-29 03:29:37 字數 1230 閱讀 1825

概要

想要隱藏某個字段

想要給返回的字段取個別名返回給前端,防止被攻擊

值為空的話就不返回該欄位 說明

@jsonformat 設定date返回的格式

@jsonformat

(pattern =

"yyyy-mm-dd hh:mm:ss"

, locale=

"zh"

, timezone =

"gmt+8"

)private date createtime;

@jsonproperty 給返回前台的字段取個別名

@jsonproperty

("account"

)//給字段取個別名,返回給前端,防止被攻擊

private string phone;

@jsoninclude(jsoninclude.include.non_null) //空值的話就不返回

忽視某個欄位不給前台返回,例如: 使用者密碼

//密碼將不會返回前端

@jsonignore

private string pwd;

示例**
public

class

user

public date getcreatetime()

public

void

setcreatetime

(date createtime)

public

intgetage()

public

void

setage

(int age)

public string getpwd()

public

void

setpwd

(string pwd)

public string getphone()

public

void

setphone

(string phone)

}

(

"/testjson"

)public object testjson()

前台資料展示

springboot學習筆記 sfl4j日誌

統一日誌 1 將系統中其他的日誌框架排除出去 如 commons logging 2 用中間包替換原來的日誌框架 3 匯入slf4j的實現 比如logback springboot中的日誌 依賴spring boot starter loggin 底層使用slf4j logback的底層實現 spr...

spring boot 學習筆記

spring boot 學習筆記 1.有時候我們在專案啟動的時候,總是需要先啟動一些初始化的類,以前比較常見的做法是寫再static塊中,spring boot提供了乙個commandlinerunner介面,實現這個介面的類總是會被優先啟動,並優先執行commandlinerunner介面中提供的...

spring boot 學習筆記

本位參考 生成spring boot 工程,通過 spring boot 快速入門 spring boot 開發web 應用 spring boot工程結構推薦 spring boot構建restful api與單元測試 spring boot中使用swagger2構建強大的restful api文...