Language Contenttype Pageencoding Prefix Uri: "Java" "Text/Html Charset Iso-8859-1" "Iso-8859-1" "C"
Language Contenttype Pageencoding Prefix Uri: "Java" "Text/Html Charset Iso-8859-1" "Iso-8859-1" "C"
Language Contenttype Pageencoding Prefix Uri: "Java" "Text/Html Charset Iso-8859-1" "Iso-8859-1" "C"
package com.app.dao;
import java.util.List;
import com.app.model.Document;
package com.app.dao.impl;
import java.util.List;
import
org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;
import com.app.dao.IDocumentDao;
import com.app.model.Document;
@Repository
public class DocumentDaoImpl implements IDocumentDao {
@Autowired
private HibernateTemplate ht;
@Override
public Integer saveDocument(Document doc) {
return (Integer) ht.save(doc);
}
@Override
public List<Object[]> getDocsIdAndNames() {
//SQL:select fid,fname from doctab
String hql="select fileId,fileName from
com.app.model.Document";
List<Object[]> data=(List<Object[]>) ht.find(hql);
return data;
}
#3 Controller:
package com.app.controller;
import java.util.List;
import
org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import
org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import
org.springframework.web.multipart.commons.CommonsMultipartFi
le;
import com.app.model.Document;
import com.app.service.IDocumentService;
@Controller
@RequestMapping("/docs")
public class DocumentController {
@Autowired
private IDocumentService service;
return "Documents";
}
@RequestMapping(value="/upload",method=RequestMethod.POST)
public String uploadDoc(
@RequestParam("fileOb") CommonsMultipartFile
file,
ModelMap map)
{
if(file!=null) {
//convert CMF data to Model class obj
Document doc=new Document();
//doc.setFileId(fileId); auto generated
doc.setFileName(file.getOriginalFilename());
doc.setFileData(file.getBytes());
int id=service.saveDocument(doc);
map.addAttribute("message", "Saved with
Id:"+id);
}
//show all uploaded docs
List<Object[]> list=service.getDocsIdAndNames();
map.addAttribute("list",list);
return "Documents";
}