Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Aphorismen
Applications
Business Economics & Admin.
My Computers
Cooking
Devices
Folders
Food
Hardware
Infos
Software Development
Sports
Operation Instructions
Todos
Test
Help
Glossary
Community portal
adaptions
Sidebar anpassen
Wiki RB4
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
SpringBoot
(section)
Page
Discussion
English
Read
Edit
View history
Toolbox
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Rest Controller=== import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController @CrossOrigin(origins="http://localhost:4200") // avoid cross origin errors in browser [[SpringBoot#.40RequestMapping|@RequestMapping]]("xyz") public class HelloWorldController { // @RequestMapping(method=RequestMethod.GET, path="/hello-world") @GetMapping(path="/hello-world") @JsonView(MenuView.NodeView.class) // tells Jackson to propagate the view class to the entities for [[Glossary#JSON|json]]-fication the return value // the same annotation has to be used at attributes in the JPA entities, which should be used for this view public <METHOD>() { ... } ====@RequestMapping==== import org.springframework.web.bind.annotation.RequestMapping; @RequestMapping("xyz") // no need of backslash, all URLs of the mappings have the prefix 'xyz', method mappings need to include the / after the prefix e.g. http://localhost/xyz/do_something public class XYZControler { @GetMapping("/do_something") public void doSomething() { ... ====@ResponseBody==== The <code>@ResponseBody</code> annotation tells a controller that the object returned is automatically serialized into JSON and passed back into the HttpResponse object. There is no need to annotate the <code>@RestController</code>-annotated controllers with the <code>@ResponseBody</code> annotation since Spring does it by default. ====Method Return Values==== public User <METHOD> public ResponseEntity<User> <METHOD> // is the same as above
Summary:
Please note that all contributions to Wiki RB4 may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Uwe Heuer Wiki New:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width