SpringBoot2 x請求註解簡單介紹(4)

2022-05-04 22:15:15 字數 2281 閱讀 2104

1.新建專案,專案中實戰講解註解作用

2.pom.xml依賴配置

<

properties

>

<

project.build.sourceencoding

>utf-8

project.build.sourceencoding

>

properties

>

<

parent

>

<

groupid

>org.springframework.boot

groupid

>

<

artifactid

>spring-boot-starter-parent

artifactid

>

<

version

>2.0.1.release

version

>

parent

>

<

dependencies

>

<

dependency

>

<

groupid

>org.springframework.boot

groupid

>

<

artifactid

>spring-boot-starter-web

artifactid

>

dependency

>

dependencies

>

package

xiaobing.demo;

import

import

public

class

public

static

void

main(string args)

}

4.demo對映

package

xiaobing.demo.controller;

import

import

org.springframework.web.bind.annotation.restcontroller;

@restcontroller

public

class

example

}

5.註解詳解

等同於:

@springbootconfiguration

@enableautoconfiguration

@componentscan

public

class

public

static

void

main(string args)

}即 @restcontroller = @controller+@responsebody

等同於:

@controller

public

class

example

@responsebody

public mapmap()

}6.啟動專案

7.常用json框架jackson返回結果的處理

指定欄位不返回:@jsonignore//響應中不展示

指定返回日期格式:@jsonformat(pattern="yyyy-mm-dd hh:mm:ss",locale="zh",timezone="gmt+8")

空字段不返回:@jsoninclude(include.non_null)

響應中指定別名:@jsonproperty

8.後續補充

基於SpringBoot 2 X整合Druid

說明 本文旨在整理springboot 2.x整合druid基礎功能,如有問題請指出 參考資料 基於springboot 2.x版本,這裡是引入druid spring boot2 starter的方式來配置,所以不需要不需要configbean來配置druid,如果引入的是druid,則需要con...

SpringBoot2 x 整合Druid詳細步驟

druid spring boot starter模式 這種方式比較簡單,不需要自己寫配置類。在匯入依賴以及配置好配置檔案yml即可。pom.xml com.alibaba druid spring boot starter 1.1.10 spring datasource url jdbc mys...

springboot2 x基礎 整合redis

在springboot中一般使用redistemplate提供的方法來操作redis。那麼使用springboot整合redis 需要那些步驟呢。環境安裝 任選 centos7 搭建redis 5單機服務 centos7 搭建 redis 5 cluster 集群服務 在專案中新增 spring b...