furthe example work
This commit is contained in:
parent
36d843329e
commit
05cf9b7541
|
@ -6,10 +6,10 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
|
|
||||||
@EnableWebMvc
|
@EnableWebMvc
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan({ "org.baeldung.controller" })
|
@ComponentScan({ "org.baeldung.web" })
|
||||||
public class MvcConfig {
|
public class WebConfig {
|
||||||
|
|
||||||
public MvcConfig() {
|
public WebConfig() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.controller;
|
package org.baeldung.web.controller;
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
@ -7,9 +7,9 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class BarController {
|
public class BarMappingExamplesController {
|
||||||
|
|
||||||
public BarController() {
|
public BarMappingExamplesController() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.controller;
|
package org.baeldung.web.controller;
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
@ -7,15 +7,15 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class FooController {
|
public class FooMappingExamplesController {
|
||||||
|
|
||||||
public FooController() {
|
public FooMappingExamplesController() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
// API
|
// API
|
||||||
|
|
||||||
// by paths
|
// mapping examples
|
||||||
|
|
||||||
@RequestMapping(value = "/foos")
|
@RequestMapping(value = "/foos")
|
||||||
@ResponseBody
|
@ResponseBody
|
|
@ -31,14 +31,16 @@ public class FooController {
|
||||||
|
|
||||||
// API
|
// API
|
||||||
|
|
||||||
// read
|
// read - single
|
||||||
|
|
||||||
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Foo findOne(@PathVariable("id") final Long id, final UriComponentsBuilder uriBuilder, final HttpServletResponse response) {
|
public Foo findById(@PathVariable("id") final Long id, final UriComponentsBuilder uriBuilder, final HttpServletResponse response) {
|
||||||
return new Foo(randomAlphabetic(6));
|
return new Foo(randomAlphabetic(6));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// read - multiple
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET)
|
@RequestMapping(method = RequestMethod.GET)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public List<Foo> findAll() {
|
public List<Foo> findAll() {
|
||||||
|
|
|
@ -1,50 +1,52 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="
|
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
|
||||||
|
xsi:schemaLocation="
|
||||||
http://java.sun.com/xml/ns/javaee
|
http://java.sun.com/xml/ns/javaee
|
||||||
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
|
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
|
||||||
|
id="WebApp_ID" version="3.0">
|
||||||
|
|
||||||
<display-name>Spring MVC Application</display-name>
|
<display-name>Spring MVC Application</display-name>
|
||||||
|
|
||||||
<!-- Spring root -->
|
<!-- Spring root -->
|
||||||
<context-param>
|
<context-param>
|
||||||
<param-name>contextClass</param-name>
|
<param-name>contextClass</param-name>
|
||||||
<param-value>
|
<param-value>
|
||||||
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
|
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
|
||||||
</param-value>
|
</param-value>
|
||||||
</context-param>
|
</context-param>
|
||||||
<context-param>
|
<context-param>
|
||||||
<param-name>contextConfigLocation</param-name>
|
<param-name>contextConfigLocation</param-name>
|
||||||
<param-value>org.baeldung.spring</param-value>
|
<param-value>org.baeldung.spring</param-value>
|
||||||
</context-param>
|
</context-param>
|
||||||
|
|
||||||
<listener>
|
<listener>
|
||||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||||
</listener>
|
</listener>
|
||||||
|
|
||||||
<!-- Spring child -->
|
<!-- Spring child -->
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>api</servlet-name>
|
<servlet-name>api</servlet-name>
|
||||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||||
<load-on-startup>1</load-on-startup>
|
<load-on-startup>1</load-on-startup>
|
||||||
</servlet>
|
</servlet>
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>api</servlet-name>
|
<servlet-name>api</servlet-name>
|
||||||
<url-pattern>/api/*</url-pattern>
|
<url-pattern>/api/*</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
<!-- Spring Security -->
|
<!-- Spring Security -->
|
||||||
<filter>
|
<filter>
|
||||||
<filter-name>springSecurityFilterChain</filter-name>
|
<filter-name>springSecurityFilterChain</filter-name>
|
||||||
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
|
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
|
||||||
</filter>
|
</filter>
|
||||||
<filter-mapping>
|
<filter-mapping>
|
||||||
<filter-name>springSecurityFilterChain</filter-name>
|
<filter-name>springSecurityFilterChain</filter-name>
|
||||||
<url-pattern>/*</url-pattern>
|
<url-pattern>/*</url-pattern>
|
||||||
</filter-mapping>
|
</filter-mapping>
|
||||||
|
|
||||||
<!-- <welcome-file-list> -->
|
<!-- <welcome-file-list> -->
|
||||||
<!-- <welcome-file>index.html</welcome-file> -->
|
<!-- <welcome-file>index.html</welcome-file> -->
|
||||||
<!-- </welcome-file-list> -->
|
<!-- </welcome-file-list> -->
|
||||||
|
|
||||||
</web-app>
|
</web-app>
|
Loading…
Reference in New Issue