• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

查看ResponseEntity源码,我们发现是它一种泛型类型。

公共类响应实体t扩展HttpEntityT {

私有最终对象状态;

/**

*创建一个仅包含状态代码的{@code ResponseEntity} .

* @param状态状态代码

*/

公共响应实体(HttpStatus状态){

this(null,null,status);

}

}

因此,我们可以使用任何类型作为响应主体:

@控制器

公共类XXXController{

@GetMapping('/hello ')

公共响应实体字符串hello(){

返回新的响应实体(“Hello World!”,HttpStatus .OK);

}

这里字符串"你好,世界!"作为字符串返回给休息端106 .我们还可以设置响应标头

@GetMapping('/customHeader ')

responseeentitystring自定义标头(){

http headers headers=new http headers();

headers.add('Custom-Header ',' foo ');

返回新的响应实体(

"自定义标头集",标头,HttpStatus .OK);

}

设置自定义标头:

@GetMapping('/customHeader ')

responseeentitystring自定义标头(){

return ResponseEntity.ok()。标题("自定义标题”、“foo”)。正文("自定义标题集")

如果将一个对象放入,自动返回一个数据字符串:

@GetMapping('/hello ')

公共响应实体字符串hello(){

返回新的响应实体(新用户(' jdon '),HttpStatus .OK);

}

[ { 'name': 'jdon'}]

当然,也可以返回数据列表:

public ResponseEntityListProcessDef repositoryProcessDefinitionsGet(){

返回新的响应实体(processdefrepo。find all(),HttpStatus .发现);

}

常用 ResponseEntity 状态:

响应实体. badRequest().build();//400: 参数不合法

ResponseEntity.notFound().build();//404:资源服务器找不到

ResponseEntity.ok(类别);//200:查询成功

参考:https://www。金淑。com/p/2a 843 c 93 af 29

https://www.jianshu.com/p/7893169a7c93

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now