@data
public
class
formattime
控制器
@restcontroller
public
class
testcontroller
}
訪問localhost:8080/test
將會返回以下結果
使用@jsonformat
註解格式化時間,應該算是乙個基本操作了,大部分開發者都應用此種方式,簡單方便。
@data
public
class
formattime
返回結果
配置全域性日期格式化處理類
@configuration
public
class
localdatetimeserializerconfig")
private string pattern;
@bean
public localdatetimeserializer localdatetimedeserializer()
@bean()
}
返回結果
這種方式可支援date
型別和localdatetime
型別並存,那麼有乙個問題就是現在全域性時間格式是yyyy-mm-dd hh:mm:ss
,但有的字段卻需要yyyy-mm-dd
格式咋整?
那就需要配合@jsonformat
註解使用,在特定的字段屬性新增@jsonformat
註解即可
#返回日期格式化
spring.jackson.date-format=yyyy-mm-dd hh:mm:ss
spring.jackson.time-zone=gmt+8
#接受引數日期格式化
spring.mvc.date-format=yyyy-mm-dd hh:mm:ss
返回結果
全域性異常處理 springBoot 全域性異常處理
先讚後看,月入百萬 springboot開發的web專案中,強調分層的概念,乙個完整的專案一般會劃分出controller層和service層。因此,為了 的可維護性,controller層 應該盡量簡潔,驗證一下引數,直接丟給service層處理即可 異常處理的方式無外乎兩種 在springboo...
springboot全域性異常捕獲
新專案中需要用到檔案上傳,有需要對上傳檔案大小進行限制,當檔案超過限制的時候,springboot框架會直接丟擲異常,不會進入你的方法中,當我們需要向前臺返回資訊的時候也無從返回,只能進行全域性捕獲檔案過大的異常,然後再返回資訊。controlleradvice public class mycon...
SpringBoot全域性異常處理
簡介通常在controller層需要去捕獲service層的異常,防止返回一些不友好的錯誤資訊到客戶端,但如果controller層每個方法都用模組化的try catch 去捕獲異常,會很難看也難維護,所以使用全域性異常比較方便 這方法是springboot封裝好了的,我們直接使用即可,普通的配置我...