Skip to content

hampalang-code/message-spring-boot-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Overview

Unify the response message body with annotations

Using

maven pom.xml

<dependency>
    <groupId>io.github.adon92</groupId>
    <artifactId>message-spring-boot-starter</artifactId>
    <version>1.0.0</version>
</dependency>
import lombok.Data;

@Data
public class User {
    private String name;
    private int age;
}

Introduce annotations @MessageReponse

@MessageResponse
@RestController
@RequestMapping
public class TestController {

    @GetMapping
    public User get() {
        User user = new User();
        user.setName("Tony");
        user.setAge(18);
        return user;
    }
}

Response Body

{
  "success": true,
  "msg": "ok",
  "data": {
    "name": "Tony",
    "age": 18
  }
}

Exception Handler

// method
public void Test(){
        // some code
        if(null==object){
        throw new MessageExcption("error message");
        }
        }

Response Body

{
  "success": true,
  "msg": "error message",
  "data": null
}
}

About

spring boot mvc http response body

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages