var itemIndex: Int = 0
@IBOutlet weak var restaurantname: UILabel!
@IBOutlet weak var offertype: UILabel!
@IBOutlet weak var aboutoffer: UILabel!
@IBOutlet weak var price: UILabel!
@IBOutlet weak var desc: UILabel!
@IBOutlet weak var dealtype: UILabel!
private var homeViewModel :QM_HomeViewModel!
init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?, withViewModel viewModel:QM_HomeViewModel) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
homeViewModel = viewModel
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
self.restaurantname.text = homeViewModel.homeModel.restaurtantname
self.offertype.text = homeViewModel.homeModel.offertype
self.aboutoffer.text = homeViewModel.homeModel.aboutoffer
self.desc.text = homeViewModel.homeModel.desc
self.price.text = homeViewModel.homeModel.price
self.dealtype.text = homeViewModel.homeModel.dealtype
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

这是我的控制器
<h3>File to upload</h3>
<form action ="upload" method="post" enctype="multipart/form-data">
<input type ="file" name ="file">
<input type ="submit" value ="submit">
</form>
答案 0 :(得分:0)
为什么不给你Spring Content去?
在http://start.spring.io/生成自己的春季启动应用程序。
将这些依赖项添加到您的pom。
的pom.xml
<dependency>
<groupId>com.github.paulcwarren</groupId>
<artifactId>spring-content-fs-boot-starter</artifactId>
<version>0.0.11</version>
</dependency>
<dependency>
<groupId>com.github.paulcwarren</groupId>
<artifactId>spring-content-rest-boot-starter</artifactId>
<version>0.0.11</version>
</dependency>
在您的主要课程中添加UploadStore
:
SpringBootApplication.java
@SpringBootApplication
public class SpringContentApplication {
public static void main(String[] args) {
SpringApplication.run(SpringContentApplication.class, args);
}
@StoreRestResource(path="upload")
public interface UploadStore extends Store<String> {
}
}
每个上传的文件都需要一个唯一的名称,因此我们生成一个guid并动态设置表单的操作。像这样更新html:
form.html
<script language="JavaScript">
window.onload = function() {
document.myform.action = get_action();
}
function get_action() {
return "upload/" + guidGenerator();
}
function guidGenerator() {
var S4 = function() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
</script>
<html>
<body>
<h3>File to upload</h3>
<form name=myform method="post" enctype="multipart/form-data">
<input type ="file" name ="file">
<input type ="submit" value ="submit">
</form>
</body>
</html>
运行您的应用程序并为UploadStore提供一个位置:
java -jar yourapp.jar --spring.content.fs.filesystemRoot=/path/to/your/store
UploadStore
和upload
不是很好的名字,因为这是一个支持POST,PUT,GET和DELETE的全功能内容服务。 GET甚至支持视频流。
还可以使用UploadStore来实现Renderable
,以便能够获取上传内容的格式;例如,获取上传的word文档的PDF。
和/或Searchable
启用全文索引(但这也需要Apache Solr)。
它可以与Spring Data结合使用,允许您关联Spring Data Entities和Spring Content Resources。
HTH