org.springframework.web.bind.ServletRequestParameterPropertyValues Java Examples

The following examples show how to use org.springframework.web.bind.ServletRequestParameterPropertyValues. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebRequestDataBinderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testNoPrefix() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.addParameter("forname", "Tony");
	request.addParameter("surname", "Blair");
	request.addParameter("age", "" + 50);

	ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
	doTestTony(pvs);
}
 
Example #2
Source File: WebRequestDataBinderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testMultipleValuesForParameter() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	String[] original = new String[] {"Tony", "Rod"};
	request.addParameter("forname", original);

	ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
	assertTrue("Found 1 parameter", pvs.getPropertyValues().length == 1);
	assertTrue("Found array value", pvs.getPropertyValue("forname").getValue() instanceof String[]);
	String[] values = (String[]) pvs.getPropertyValue("forname").getValue();
	assertEquals("Correct values", Arrays.asList(values), Arrays.asList(original));
}
 
Example #3
Source File: WebRequestDataBinderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testNoPrefix() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.addParameter("forname", "Tony");
	request.addParameter("surname", "Blair");
	request.addParameter("age", "" + 50);

	ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
	doTestTony(pvs);
}
 
Example #4
Source File: WebRequestDataBinderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testMultipleValuesForParameter() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	String[] original = new String[] {"Tony", "Rod"};
	request.addParameter("forname", original);

	ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
	assertTrue("Found 1 parameter", pvs.getPropertyValues().length == 1);
	assertTrue("Found array value", pvs.getPropertyValue("forname").getValue() instanceof String[]);
	String[] values = (String[]) pvs.getPropertyValue("forname").getValue();
	assertEquals("Correct values", Arrays.asList(values), Arrays.asList(original));
}
 
Example #5
Source File: WebRequestDataBinderTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoPrefix() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.addParameter("forname", "Tony");
	request.addParameter("surname", "Blair");
	request.addParameter("age", "" + 50);

	ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
	doTestTony(pvs);
}
 
Example #6
Source File: WebRequestDataBinderTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultipleValuesForParameter() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	String[] original = new String[] {"Tony", "Rod"};
	request.addParameter("forname", original);

	ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
	assertTrue("Found 1 parameter", pvs.getPropertyValues().length == 1);
	assertTrue("Found array value", pvs.getPropertyValue("forname").getValue() instanceof String[]);
	String[] values = (String[]) pvs.getPropertyValue("forname").getValue();
	assertEquals("Correct values", Arrays.asList(values), Arrays.asList(original));
}
 
Example #7
Source File: EntityController.java    From QuickProject with Apache License 2.0 5 votes vote down vote up
public Entity parseModel(HttpServletRequest request) {
    Object o = null;
    try {
        o = getEntityClass().newInstance();
    } catch (Exception e) {
        throw new RuntimeException("无法创建类的实例:" + getEntityClass());
    }
    DataBinder dataBinder = new DataBinder(o);
    dataBinder.registerCustomEditor(Time.class, new TimeEditor());
    MutablePropertyValues mpvs = new ServletRequestParameterPropertyValues(request);
    dataBinder.bind(mpvs);

    return (Entity) o;
}
 
Example #8
Source File: WebRequestDataBinderTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void testNoParameters() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
	assertTrue("Found no parameters", pvs.getPropertyValues().length == 0);
}
 
Example #9
Source File: WebRequestDataBinderTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void testNoParameters() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
	assertTrue("Found no parameters", pvs.getPropertyValues().length == 0);
}
 
Example #10
Source File: WebRequestDataBinderTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void testNoParameters() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
	assertTrue("Found no parameters", pvs.getPropertyValues().length == 0);
}