本文整理汇总了Java中org.springframework.web.multipart.support.StringMultipartFileEditor类的典型用法代码示例。如果您正苦于以下问题:Java StringMultipartFileEditor类的具体用法?Java StringMultipartFileEditor怎么用?Java StringMultipartFileEditor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringMultipartFileEditor类属于org.springframework.web.multipart.support包,在下文中一共展示了StringMultipartFileEditor类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMultipartFileAsString
import org.springframework.web.multipart.support.StringMultipartFileEditor; //导入依赖的package包/类
@Test
public void testMultipartFileAsString() {
TestBean target = new TestBean();
WebRequestDataBinder binder = new WebRequestDataBinder(target);
binder.registerCustomEditor(String.class, new StringMultipartFileEditor());
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.addFile(new MockMultipartFile("name", "Juergen".getBytes()));
binder.bind(new ServletWebRequest(request));
assertEquals("Juergen", target.getName());
}
示例2: testMultipartFileAsStringArray
import org.springframework.web.multipart.support.StringMultipartFileEditor; //导入依赖的package包/类
@Test
public void testMultipartFileAsStringArray() {
TestBean target = new TestBean();
WebRequestDataBinder binder = new WebRequestDataBinder(target);
binder.registerCustomEditor(String.class, new StringMultipartFileEditor());
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.addFile(new MockMultipartFile("stringArray", "Juergen".getBytes()));
binder.bind(new ServletWebRequest(request));
assertEquals(1, target.getStringArray().length);
assertEquals("Juergen", target.getStringArray()[0]);
}
示例3: testMultipartFilesAsStringArray
import org.springframework.web.multipart.support.StringMultipartFileEditor; //导入依赖的package包/类
@Test
public void testMultipartFilesAsStringArray() {
TestBean target = new TestBean();
WebRequestDataBinder binder = new WebRequestDataBinder(target);
binder.registerCustomEditor(String.class, new StringMultipartFileEditor());
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.addFile(new MockMultipartFile("stringArray", "Juergen".getBytes()));
request.addFile(new MockMultipartFile("stringArray", "Eva".getBytes()));
binder.bind(new ServletWebRequest(request));
assertEquals(2, target.getStringArray().length);
assertEquals("Juergen", target.getStringArray()[0]);
assertEquals("Eva", target.getStringArray()[1]);
}
示例4: createBinder
import org.springframework.web.multipart.support.StringMultipartFileEditor; //导入依赖的package包/类
/**
* Utility method for creating a GrailsDataBinder instance
*
* @param target The target object to bind to
* @param objectName The name of the object
* @return A GrailsDataBinder instance
*/
public static GrailsDataBinder createBinder(Object target, String objectName) {
GrailsDataBinder binder = new GrailsDataBinder(target, objectName);
binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
binder.registerCustomEditor(String.class, new StringMultipartFileEditor());
binder.registerCustomEditor(Currency.class, new CurrencyEditor());
binder.registerCustomEditor(Locale.class, new LocaleEditor());
binder.registerCustomEditor(TimeZone.class, new TimeZoneEditor());
binder.registerCustomEditor(URI.class, new UriEditor());
registerCustomEditors(binder);
return binder;
}
示例5: initBinder
import org.springframework.web.multipart.support.StringMultipartFileEditor; //导入依赖的package包/类
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(String.class, new StringMultipartFileEditor());
}
示例6: doTestBinding
import org.springframework.web.multipart.support.StringMultipartFileEditor; //导入依赖的package包/类
private void doTestBinding(MockCommonsMultipartResolver resolver, MockHttpServletRequest originalRequest,
MultipartHttpServletRequest request) throws UnsupportedEncodingException {
MultipartTestBean1 mtb1 = new MultipartTestBean1();
assertArrayEquals(null, mtb1.getField1());
assertEquals(null, mtb1.getField2());
ServletRequestDataBinder binder = new ServletRequestDataBinder(mtb1, "mybean");
binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
binder.bind(request);
List<MultipartFile> file1List = request.getFiles("field1");
CommonsMultipartFile file1a = (CommonsMultipartFile) file1List.get(0);
CommonsMultipartFile file1b = (CommonsMultipartFile) file1List.get(1);
CommonsMultipartFile file2 = (CommonsMultipartFile) request.getFile("field2");
assertEquals(file1a, mtb1.getField1()[0]);
assertEquals(file1b, mtb1.getField1()[1]);
assertEquals(new String(file2.getBytes()), new String(mtb1.getField2()));
MultipartTestBean2 mtb2 = new MultipartTestBean2();
assertArrayEquals(null, mtb2.getField1());
assertEquals(null, mtb2.getField2());
binder = new ServletRequestDataBinder(mtb2, "mybean");
binder.registerCustomEditor(String.class, "field1", new StringMultipartFileEditor());
binder.registerCustomEditor(String.class, "field2", new StringMultipartFileEditor("UTF-16"));
binder.bind(request);
assertEquals(new String(file1a.getBytes()), mtb2.getField1()[0]);
assertEquals(new String(file1b.getBytes()), mtb2.getField1()[1]);
assertEquals(new String(file2.getBytes(), "UTF-16"), mtb2.getField2());
resolver.cleanupMultipart(request);
assertTrue(((MockFileItem) file1a.getFileItem()).deleted);
assertTrue(((MockFileItem) file1b.getFileItem()).deleted);
assertTrue(((MockFileItem) file2.getFileItem()).deleted);
resolver.setEmpty(true);
request = resolver.resolveMultipart(originalRequest);
binder.setBindEmptyMultipartFiles(false);
String firstBound = mtb2.getField2();
binder.bind(request);
assertTrue(mtb2.getField2().length() > 0);
assertEquals(firstBound, mtb2.getField2());
request = resolver.resolveMultipart(originalRequest);
binder.setBindEmptyMultipartFiles(true);
binder.bind(request);
assertTrue(mtb2.getField2().length() == 0);
}