我想将上传的图像保存到Tomcat上部署的Spring 3 MVC应用程序中的特定文件夹中
我的问题是我无法将上传的图像文件保存到运行applciation的主机.
这是我尝试过的:
private void saveFile(MultipartFile multipartFile, int id) throws Exception {
String destination = "/images/" + id + "/" + multipartFile.getOriginalFilename();
File file = new File(destination);
multipartFile.transferTo(file);
}
Run Code Online (Sandbox Code Playgroud)
结果:FileNotFoundException - 是的,我确实想要创建这个文件!?!
我尝试使用context.getRealPath
或getResources("destination")
,但没有任何成功.
如何使用我的多部分文件的内容在我的应用程序的特定文件夹中创建新文件?
以下是在目标c中工作:
// Base Class in ClassA.h and ClassA.m
@interface ClassA : NSObject
- (NSString *) myMethod;
@end
@implementation ClassA
- (NSString*) myMethod { return @"A"; }
@end
//Category in ClassA+CategoryB.h and ClassA+CategoryB.m
@interface ClassA (CategoryB)
- (NSString *) myMethod;
@end
@implementation ClassA (CategoryB)
- (NSString*) myMethod { return @"B"; }
@end
Run Code Online (Sandbox Code Playgroud)
问题是,如果我只是导入ClassA.h并发送消息
[myClassA myMethod]; //returns B
Run Code Online (Sandbox Code Playgroud)
这为什么会回归B
?我没有导入ClassA + CategoryB
即便如此,如果我做了以下事情:
// Base Class in ClassA.h and ClassA.m
@interface ClassA : NSObject
- (NSString *) myMethod;
- (NSString *) …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个iphone应用程序,我直接使用AVFoundation通过相机捕获视频.
我已经实现了一项功能来tap to focus
为用户启用该功能.
- (void) focus:(CGPoint) aPoint;
{
#if HAS_AVFF
Class captureDeviceClass = NSClassFromString(@"AVCaptureDevice");
if (captureDeviceClass != nil) {
AVCaptureDevice *device = [captureDeviceClass defaultDeviceWithMediaType:AVMediaTypeVideo];
if([device isFocusPointOfInterestSupported] &&
[device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) {
CGRect screenRect = [[UIScreen mainScreen] bounds];
double screenWidth = screenRect.size.width;
double screenHeight = screenRect.size.height;
double focus_x = aPoint.x/screenWidth;
double focus_y = aPoint.y/screenHeight;
if([device lockForConfiguration:nil]) {
[device setFocusPointOfInterest:CGPointMake(focus_x,focus_y)];
[device setFocusMode:AVCaptureFocusModeAutoFocus];
if ([device isExposureModeSupported:AVCaptureExposureModeAutoExpose]){
[device setExposureMode:AVCaptureExposureModeAutoExpose];
}
[device unlockForConfiguration];
}
}
}
#endif
}
Run Code Online (Sandbox Code Playgroud)
到目前为止一直很好,但我错过了照片应用程序中的反馈矩形.有没有办法告诉AVFoundation Framework显示这个反馈矩形还是我必须自己实现这个功能?
我有一个简单的登录视图,如下所示.
如果任何EditText
增益集中,键盘将显示(软).红色虚线应勾勒出这种行为:
我需要的是,键盘显示时,底部的按钮(注册和帮助)是不可见的.登录按钮的底端应在键盘上,这样既EditTexts
与该Login Button
可见.
如果可能,最多应该看到徽标的一半(取决于屏幕尺寸)
如果可能的话,定义一个额外的布局xml,如"键盘可见",这将是完美的.
我没有发现任何migration rules
改变deletion rule
a的情况managedObjects relationship
我最初的coredata模型包含一个有关系的实体.这种关系的删除规则是cascade
.我不得不改变这种行为Nullify
.
因此我创建了一个new version of my coredata model
但没有任何轻量级迁移,它仍然有效.所以我wounder如果我应该做我的加入模型,或者如果更改删除规则(例如从一个新的版本cascade
来nullify
)并不影响/需要任何迁移.
有什么建议?
我正在尝试使用spring 3上传一个带有一个参数的文件.
这是我的控制器方法,它应该启用此服务:
@RequestMapping(value="/{id}", method = RequestMethod.PUT, headers="content-type=multipart/form-data")
public ResponseEntity<String> uploadImageWithJsonParamater(@PathVariable("id") Long id, @RequestParam String json, @RequestParam MultipartFile customerSignFile) {
//...
}
Run Code Online (Sandbox Code Playgroud)
问题是,服务器无法调度到此方法:MissingServletRequestParameterException:必需的字符串参数'json'不存在
如果我将RequestMethod从PUT更改为POST,一切都很好.那么有人知道这个问题吗?
似乎不允许通过PUT传输表单数据.
我调试了一下,以下方法在PUT情况下返回false,但在POST情况下为true:
public boolean isMultipart(HttpServletRequest request) {
return (request != null && ServletFileUpload.isMultipartContent(request));
}
Run Code Online (Sandbox Code Playgroud)
我将不胜感激任何帮助!
提前致谢!
我试图从用户可以绘制的视图中获取图像,或者添加一些其他视图.iPad1和iPad到目前为止一切正常.但在iPad3上它像狗一样运行.我只是使用图层renderInContext方法.
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(self.viewDrawableViewContainer.frame.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(self.viewDrawableViewContainer.frame.size);
[self.viewDrawableViewContainer.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)
我知道这可能是由cpu引起的,它等于ipad2,但需要大约1秒钟.用户绘制或添加的越多,渲染所需的时间就越长.有时长达5秒,这是非常不可接受的.那么有什么选择来提高性能吗?有可能设置较小的渲染质量 - 我不需要在最高视网膜分辨率下渲染......
我将不胜感激任何帮助!提前致谢
我正在尝试使用 junit 测试我的应用程序。
因此,我设置了以下课程:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "/META-INF/spring/applicationContext-test.xml" )
@TransactionConfiguration
@Transactional
public class DispatcherServletTest extends AbstractJUnit4SpringContextTests {
private MockHttpServletRequest request;
private MockHttpServletResponse response;
private DispatcherServlet dispatcher;
@Before
public void setUp() throws Exception {
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
MockServletConfig config = new MockServletConfig("myapp");
config.addInitParameter("contextConfigLocation","classpath*:webmvc-config.xml");
dispatcher = new DispatcherServlet();
dispatcher.init(config);
}
//test cases
Run Code Online (Sandbox Code Playgroud)
}
所以问题是,我的调度程序 servlet 似乎无法向我的任何控制器发送任何请求。
我认为配置中有一些东西 - contextConfigurationLocation。看起来他可以找到文件(否则会抛出异常),但不会加载任何配置
记录者说:
org.springframework.web.servlet.PageNotFound - 未找到带有 URI [http://localhost:8080/myapp/abc] 的 HTTP 请求的映射
但我完全不知道出了什么问题......
我将不胜感激任何帮助!
提前致谢
我想在我的钥匙串中保存两个密码(一个app pin和一个后端pin),我想知道这应该如何工作.
我使用KeychainItemWrapper与不同的标识符.
KeychainItemWrapper *kcw1 = [[KeychainItemWrapper alloc] initWithIdentifier:id1 accessGroup:nil];
KeychainItemWrapper *kcw2 = [[KeychainItemWrapper alloc] initWithIdentifier:id2 accessGroup:nil];
Run Code Online (Sandbox Code Playgroud)
我正在使用其中一个来保存和检索应用程序或后端引脚.
我用 :
[self.kcw1 setObject:aVerifyCode forKey:(__bridge id) kSecValueData]
[self.kcw2 setObject:aAppPin forKey:(__bridge id) kSecValueData]
Run Code Online (Sandbox Code Playgroud)
但它不起作用 - 结果是-25299 - 指定的项目已经存在于钥匙串中
那么如何在钥匙串中保存多个密码呢?
我正在使用我的一些图像的集合视图.
每个图像应以屏幕大小显示,因此一个单元格具有屏幕宽度.在minimumInterItemSpacing
该FlowLayout中的是25.所以,现在的问题是,如果我滚动,收集视图不滚动到下一个图像的开始,但对interItemSpacing的开始.
我们举个例子:
Image/Cell width = 320
CollectionView's interItemSpacing = 25
Run Code Online (Sandbox Code Playgroud)
如果我滚动一页,则滚动视图内容偏移为320而不是345意味着第二个单元不在屏幕的中心.
如何解决这个问题?有什么建议?
ios ×5
ipad ×4
iphone ×4
spring ×3
android ×1
avfoundation ×1
categories ×1
core-data ×1
dispatcher ×1
file ×1
file-upload ×1
ios5 ×1
ipad-3 ×1
junit4 ×1
keyboard ×1
keychain ×1
migration ×1
objective-c ×1
scrollview ×1
spring-3 ×1
spring-mvc ×1
tomcat ×1