Created
June 20, 2018 11:57
-
-
Save peanutpi/2c40389695bb0890957b5d70204d8987 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.jacksondemo.dto; | |
import java.time.LocalDate; | |
import java.util.ArrayList; | |
import java.util.List; | |
import javax.validation.constraints.NotNull; | |
import javax.validation.constraints.Size; | |
public class Message { | |
private Long id; | |
private LocalDate created; | |
private String title; | |
private User author; | |
private String body = "hola!"; | |
public Long getId() { | |
return id; | |
} | |
public void setId(Long id) { | |
this.id = id; | |
} | |
public LocalDate getCreated() { | |
return created; | |
} | |
public void setCreated(LocalDate created) { | |
this.created = created; | |
} | |
public String getTitle() { | |
return title; | |
} | |
public void setTitle(String title) { | |
this.title = title; | |
} | |
public User getAuthor() { | |
return author; | |
} | |
public void setAuthor(User author) { | |
this.author = author; | |
} | |
public String getBody() { | |
return body; | |
} | |
public void setBody(String body) { | |
this.body = body; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.jacksondemo.rest; | |
import javax.validation.Valid; | |
import org.springframework.web.bind.annotation.PostMapping; | |
import org.springframework.web.bind.annotation.RequestBody; | |
import org.springframework.web.bind.annotation.RestController; | |
import com.example.jacksondemo.dto.Message; | |
@RestController | |
public class MessageController { | |
@PostMapping("/") | |
public void createMessage(@Valid @RequestBody Message message) { | |
System.out.println("Success ! " + message.getBody()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -X POST \ | |
http://localhost:8080/ \ | |
-H 'cache-control: no-cache' \ | |
-H 'content-type: application/json' \ | |
-d '{ | |
"title": "abc" | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment