Last active
October 11, 2023 20:07
-
-
Save joshlong/6431608 to your computer and use it in GitHub Desktop.
Revisions
-
joshlong revised this gist
Sep 4, 2013 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -37,8 +37,10 @@ class RestConfiguration { */ @Controller class StatusController { @RequestMapping(value= "/customers/{customerId}", method= RequestMethod.GET) public @ResponseBody Customer loadCustomer(@PathVariable long customerId ) { // return a POJO Customer somehow (perhaps look it up in a database?) return someCustomer ; } } -
joshlong revised this gist
Sep 4, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -37,7 +37,7 @@ class RestConfiguration { */ @Controller class StatusController { @RequestMapping(value= "/customers/{customerId}", method= RequestMethod.GET) public @ResponseBody Customer loadCustomer(@PathVariable long customerId ) { return customerRepository.findCustomerById ( customerId ); // any POJO } -
joshlong created this gist
Sep 4, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ /** * <p>This will be picked up in a Servlet 3 environment like Apache Tomcat 7. * * <p>This replaces <code>web.xml</code>. * */ public class MvcRestApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override protected Class<?> [] getRootConfigClasses() { return new Class<?>[]{}; } @Override protected Class<?>[] getServletConfigClasses() { return new Class<?>[]{ RestConfiguration.class }; } @Override protected String[] getServletMappings(){ return new String[]{"/"}; } } /** * Installs Spring MVC and all the required support for JSON assuming * Jackson's on the CLASSPATH */ @EnableWebMvc @ComponentScan @Configuration class RestConfiguration { // that's all! } /** * A simple Spring MVC REST controller. The returned value (Customer) will * be converted into JSON if the client signals that it can read JSON (using the * <CODE>ACCEPT</CODE> header.) */ @Controller class StatusController { @RequestMapping(value="/customers/{customerId}", method= RequestMethod.GET) public @ResponseBody Customer loadCustomer(@PathVariable long customerId ) { return customerRepository.findCustomerById ( customerId ); // any POJO } }