Move A Quick Guide to Spring MVC Matrix Variables
This commit is contained in:
parent
daa42ab3a0
commit
2d08a88ec0
@ -2,4 +2,5 @@
|
||||
|
||||
- [Cache Headers in Spring MVC](https://www.baeldung.com/spring-mvc-cache-headers)
|
||||
- [Working with Date Parameters in Spring](https://www.baeldung.com/spring-date-parameters)
|
||||
- [Spring MVC @PathVariable with a dot (.) gets truncated](https://www.baeldung.com/spring-mvc-pathvariable-dot)
|
||||
- [Spring MVC @PathVariable with a dot (.) gets truncated](https://www.baeldung.com/spring-mvc-pathvariable-dot)
|
||||
- [A Quick Guide to Spring MVC Matrix Variables](https://www.baeldung.com/spring-mvc-matrix-variables)
|
@ -26,6 +26,11 @@
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>${spring.mvc.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -15,7 +15,7 @@ import java.util.concurrent.TimeUnit;
|
||||
@EnableWebMvc
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = {"com.baeldung.cache"})
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
public class CacheWebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addViewControllers(final ViewControllerRegistry registry) {
|
@ -0,0 +1,18 @@
|
||||
package com.baeldung.matrix.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.util.UrlPathHelper;
|
||||
|
||||
@Configuration
|
||||
public class MatrixWebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void configurePathMatch(PathMatchConfigurer configurer) {
|
||||
final UrlPathHelper urlPathHelper = new UrlPathHelper();
|
||||
urlPathHelper.setRemoveSemicolonContent(false);
|
||||
|
||||
configurer.setUrlPathHelper(urlPathHelper);
|
||||
}
|
||||
}
|
@ -1,23 +1,16 @@
|
||||
package com.baeldung.web.controller;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
package com.baeldung.matrix.controller;
|
||||
|
||||
import com.baeldung.matrix.model.Company;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.MatrixVariable;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.baeldung.model.Company;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
public class CompanyController {
|
@ -1,32 +1,22 @@
|
||||
package com.baeldung.web.controller;
|
||||
package com.baeldung.matrix.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baeldung.matrix.model.Employee;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.MatrixVariable;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.SessionAttributes;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.baeldung.model.Employee;
|
||||
import java.util.*;
|
||||
|
||||
@SessionAttributes("employees")
|
||||
@Controller
|
||||
public class EmployeeController {
|
||||
|
||||
Map<Long, Employee> employeeMap = new HashMap<>();
|
||||
public Map<Long, Employee> employeeMap = new HashMap<>();
|
||||
|
||||
@ModelAttribute("employees")
|
||||
public void initEmployees() {
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.model;
|
||||
package com.baeldung.matrix.model;
|
||||
|
||||
public class Company {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.model;
|
||||
package com.baeldung.matrix.model;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
@ -11,7 +11,17 @@
|
||||
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<!-- <mvc:annotation-driven/>-->
|
||||
|
||||
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||
<property name="prefix">
|
||||
<value>/WEB-INF/view/</value>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<value>.jsp</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<context:component-scan base-package="com.baeldung"/>
|
||||
</beans>
|
@ -19,7 +19,7 @@ import static org.springframework.http.HttpHeaders.IF_UNMODIFIED_SINCE;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@WebAppConfiguration
|
||||
@ContextConfiguration(classes = {WebConfig.class, WebConfig.class})
|
||||
@ContextConfiguration(classes = {CacheWebConfig.class, CacheWebConfig.class})
|
||||
public class CacheControlControllerIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
|
@ -1,11 +1,7 @@
|
||||
package com.baeldung.web.controller;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||
package com.baeldung.matrix;
|
||||
|
||||
import com.baeldung.matrix.config.MatrixWebConfig;
|
||||
import com.baeldung.matrix.controller.EmployeeController;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -18,11 +14,13 @@ import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import com.baeldung.spring.web.config.WebConfig;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@WebAppConfiguration
|
||||
@ContextConfiguration(classes = WebConfig.class)
|
||||
@ContextConfiguration(classes = { MatrixWebConfig.class, EmployeeController.class })
|
||||
public class EmployeeMvcIntegrationTest {
|
||||
|
||||
@Autowired
|
@ -1,5 +1,8 @@
|
||||
package com.baeldung.web.controller;
|
||||
package com.baeldung.matrix;
|
||||
|
||||
import com.baeldung.matrix.config.MatrixWebConfig;
|
||||
import com.baeldung.matrix.controller.EmployeeController;
|
||||
import com.baeldung.matrix.model.Employee;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -9,12 +12,9 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import com.baeldung.model.Employee;
|
||||
import com.baeldung.spring.web.config.WebConfig;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@WebAppConfiguration
|
||||
@ContextConfiguration(classes = WebConfig.class)
|
||||
@ContextConfiguration(classes = { MatrixWebConfig.class, EmployeeController.class })
|
||||
public class EmployeeNoMvcIntegrationTest {
|
||||
|
||||
@Autowired
|
@ -8,7 +8,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant Articles:
|
||||
- [Integration Testing in Spring](https://www.baeldung.com/integration-testing-in-spring)
|
||||
- [A Quick Guide to Spring MVC Matrix Variables](https://www.baeldung.com/spring-mvc-matrix-variables)
|
||||
- [File Upload with Spring MVC](https://www.baeldung.com/spring-file-upload)
|
||||
- [Introduction to HtmlUnit](https://www.baeldung.com/htmlunit)
|
||||
- [Upload and Display Excel Files with Spring MVC](https://www.baeldung.com/spring-mvc-excel-files)
|
||||
|
Loading…
x
Reference in New Issue
Block a user