springboot(2)-階段篇

來源:互聯網
上載者:User

標籤:boot   public   filters   span   esc   config   spring   字元   需要   

web開發

spring boot web開發非常的簡單,其中包括常用的json輸出、filters、property、log等

json 介面開發

在以前的spring 開發的時候需要我們提供json介面的時候需要做那些配置呢

  1. 添加 jackjson 等相關jar包
  2. 配置spring controller掃描
  3. 對接的方法添加@ResponseBody

如果我們需要使用頁面開發只要使用 @Controller ,下面會結合模板來說明

自訂Filter

我們常常在項目中會使用filters用於錄調用日誌、排除有XSS威脅的字元、執行許可權驗證等等。Spring Boot自動添加了OrderedCharacterEncodingFilter和HiddenHttpMethodFilter,並且我們可以自訂Filter。

兩個步驟:

  1. 實現Filter介面,實現Filter方法
  2. 添加@Configuration 註解,將自訂Filter加入過濾鏈
自訂Property

在web開發的過程中,我經常需要自訂一些設定檔,如何使用呢

配置在application.properties中
com.neo.title=標題com.neo.description=表述
@Componentpublic class NeoProperties {@Value("${com.neo.title}")private String title;@Value("${com.neo.description}")private String description;}
 

springboot(2)-階段篇

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.