Java generation and export word resume

Create a word file content into the format you want to generate a file and then generates .ftl
did not talk much on the code!
@Override
public void exportword (the HttpServletResponse Response, the HttpServletRequest Request, Long ID) throws IOException {
String conf_filename this.getClass = (). GetClassLoader (). The getResource ( ""). GetPath ()
+ the System.getProperty ( "File.separator" ) + "fdfs_client.conf";
// ** initial configuration file //
the configuration the configuration = new new the configuration ();
//
* setting coding //
configuration.setDefaultEncoding ( "UTF-8");
//
* my ftl file It is on the D drive of * // **
String = Tools.getvalue the FileDirectory ( "project_maindir");
// the FileDirectory String = "D: \";
// load the file ** //
configuration.setDirectoryForTemplateLoading (new new File (the FileDirectory));
//
* Load Template //
Template Template = configuration.getTemplate ( "AA.ftl");
//
* ready data //
the Map <String, Object> = Datamap new new HashMap < String, Object> ();
the Map <String, Object> = new new the HashMap Map <String, Object> ();
// check out the CV's information according to the member ID
ResumeInformation resumeVo = resumeInformationMapper.findResumePreviewByMid (ID);
IF (resumeVo.getPostnature ! () = null && "!" the equals (resumeVo.getPostnature ())) {.
, ") String [] = resumeVo.getPostnature IDS () Split (.";
// parameter name in accordance with the IDS query tile
String postnature = paramDictionaryMapper.findParamById (IDS);
resumeVo.setPostnatureString (postnature);
}
IF (! resumeVo.getUpdateTime () = null) {
resumeVo.setUpdateHours (DateUtils.DateToString (resumeVo.getUpdateTime (), DateStyle.YYYY_MM_DD));
}
// check out according to the member ID experience `
List workExperienceList workExperienceMapper.findWorkExperienceListByMid = ( the above mentioned id);
// query based on the member ID project experience
List projectExperienceList = projectExperienceMapper.findProjectExperienceListByMid (the above mentioned id);
// check out the educational experience based on membership ID
List educationExperienceList = educationExperienceMapper.findEducationExperienceListByMid (the above mentioned id);
// according Member ID check out the training experience
trainExperienceList = trainExperienceMapper.findTrainExperienceListByMid List (the above mentioned id);
// check out the website works according to Member ID
List worksWebsiteList = worksWebsiteMapper.findWorksWebsiteListByMid (the above mentioned id);
map.put ( "resumeVo", resumeVo);
if(resumeVo.getPhotoUrl()!=null){
String fileData = resumeVo.getPhotoUrl();
fileData = fileData.substring(7, fileData.length());
String firstName=fileData.substring(fileData.lastIndexOf(’/’)+1);
int indexOf = fileData.indexOf("/");
String url2 = fileData.substring(indexOf+1);
int indexOf2 = url2.indexOf("/");
String group = url2.substring(0, indexOf2);
String path = url2.substring(indexOf2+1);
//循环下载路径
String urlshared = App.downloadFiles(group, path, conf_filename, request,firstName);
InputStream in = null;
byte[] data = null;
try {
in = new FileInputStream(urlshared);
data = new byte[in.available()];
in.read(data);
in.close ();
} the catch (Exception E) {
e.printStackTrace ();
} the finally {
IF (= null in!) {
in.close ();
}
}
//
* base64-encoded bits //
Base64Encoder = Encoder Base64Encoder new new ();
dataMap.put ( "IMG", encoder.encode (Data));
} the else {
//
* image path //
.. = Request.getSession the imagePath String () GetServletContext () the getRealPath ( "/ Resources / images / defaultHeadimg.png "); // get the path of the image in the project
//
* into the picture // * **
the InputStream in = null;
byte [] Data = null;
the try {
in the FileInputStream new new = (the imagePath) ;
Data = new new byte [in.available ()];
in.read (Data);
in.close ();
} the catch (Exception E) {
e.printStackTrace ();
} the finally {
IF (= null in!) {
in.close ();
}
}
// ** base64-encoded bits //
Base64Encoder Encoder Base64Encoder new new = ();
dataMap.put ( "IMG", encoder.encode (Data));
}
// name
dataMap.put ( "name", resumeVo.getRealName ());
// gender
dataMap.put ( "sex ", resumeVo.getSexs ());
// Age
dataMap.put (" Age ", resumeVo.getAge ());
// work experience
! IF (resumeVo.getWorkExe () = null) {
IF (resumeVo.getWorkExe () 0 ==) {
dataMap.put ( "workExe", "less than one year of work experience");
} the else {
dataMap.put ( "workExe", resumeVo.getWorkExe () + "years of experience");
}
the else {}
dataMap.put ( "workExe", "no experience");
}
// now living city
dataMap.put ( "nowCity", resumeVo.getNowCity ());
// hide the middle four mobile phone number
String s resumeVo.getPhone = ();
String s.replaceAll the replaceAll = ( "(\ {D}. 3) \. 4 {D} (\. 4 {D})", "$. 1
*** $ 2");
// phone number
dataMap .put ( "Phone", the replaceAll);
// mail
IF (!. resumeVo.getEmail () = null && resumeVo.getEmail () length ()> 0) {
the StringBuilder the StringBuilder In email new new = ();
int NUM;
String STR = "";
email.append (resumeVo.getEmail ());
NUM = email.indexOf ( "@");
for (int I = 0; I <NUM; I ++) {
STR + STR = "*";
}
In Email email.replace = (. 3, NUM, STR);
the System.out.println(email);
dataMap.put ( "In Email", In Email);
} the else {
dataMap.put ( "In Email", "");
}
// nature
dataMap.put ( "postnature", resumeVo.getPostnatureString ());
// desired operating place
dataMap.put ( "workCity", resumeVo.getWorkCity ());
// desired career
dataMap.put ( "posiName", resumeVo.getPosiName ());
// expect industry
dataMap.put ( "industryName", resumeVo.getIndustryName ());
// expected salary
dataMap.put ( "Offers", resumeVo.getOffers ());
// self-evaluation
dataMap.put ( "Explored", resumeVo.getExplored ());
// split individual label
if (resumeVo ! .getPersonTag () = null) {
String personTag = resumeVo.getPersonTag () the replaceAll ( ",", ".");
dataMap.put ( "personTag", personTag);
} the else {
dataMap.put ( "personTag", "");
}
// experience
dataMap.put ( "workExperienceList", workExperienceList);
// query based on the member ID project experience
dataMap.put ( "projectExperienceList", projectExperienceList);
// according Member ID check out the educational experience
dataMap.put ( "educationExperienceList", educationExperienceList);
// check out the training experience based on membership ID
dataMap.put ( "trainExperienceList", trainExperienceList);
// check out the website works according to the member ID
dataMap.put ( "worksWebsiteList", worksWebsiteList);
// the Map <String, the Map <String, Object >> dataMaps new new LinkedHashMap = <String, the Map <String, Object >> ();
// List List = studymetarialdetailService.findstudymetarials (sId, docId );
// loop through List
/ * for (studymetarialdetail studymetarialdetail: List) {
String fileData = studymetarialdetail.getFirstPath();
String description = studymetarialdetail.getDescrip()==null?"":studymetarialdetail.getDescrip();

		String firstName=fileData.substring(fileData.lastIndexOf('/')+1);
		int indexOf = fileData.indexOf("/");
		String url2 = fileData.substring(indexOf+1);
		int indexOf2 = url2.indexOf("/");
		String group = url2.substring(0, indexOf2);
		String path = url2.substring(indexOf2+1);
		//循环下载路径
		String urlshared = App.downloadFiles(group, path, conf_filename, request,firstName);
	    InputStream in = null;
        byte[] data = null;
	        try {
	            in = new FileInputStream(urlshared);
	            data = new byte[in.available()];
	            in.read(data);
	            in.close();
	        } catch (Exception e) {
	            e.printStackTrace();
	        }finally {
	            if(in != null){
	                in.close();
	            }
	        }
	        //** 进行base64位编码 **//*
	        BASE64Encoder encoder = new BASE64Encoder();
	        //** 在ftl文件中有${textDeal}这个标签**//*
	        //dataMap.put("textDeal","一下省略一万字");
	        //** 图片数据**//*
	        dataMap.put("描述"+i+":"+description,encoder.encode(data));
	        i++;
	}
	dataMaps.put("dataMaps", dataMap);*/
	//dataMap.put("images", images);
	//dataMap.put("titles", titles);
      //** 指定输出word文件的路径 **//*
	long currentTime = System.currentTimeMillis();
	//SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
	//Date date = new Date(currentTime);
		String filename = "JM"+currentTime+".doc";
        String outFilePath = Tools.getPropertie("upload.down")+filename;
      //  String downpath = Tools.getvalue("upload.down");
        File docFile = new File(outFilePath);
        FileOutputStream fos = new FileOutputStream(docFile);
        Writer out = new BufferedWriter(new OutputStreamWriter(fos, "utf-8"),10240);
        try {
			template.process(dataMap, out);;
		} catch (TemplateException e) {
			e.printStackTrace();
		}

        if(out != null){
            out.close();
        }
        Tools.fileDown(response, outFilePath, filename);
	}

最后一步是文件下载 贴上代码
/**
* 文件流下载
* @throws IOException
*/
public static void fileDown(HttpServletResponse resp,String filepath,String filename) throws IOException{
resp.setContentType(“application/force-download”);
InputStream in = new FileInputStream(filepath);
resp.setHeader(“Content-Disposition”, “attachment;filename=”" + filename + “”");
resp.setContentLength(in.available());
OutputStream out = resp.getOutputStream();
byte[] b = new byte[1024];
int len = 0;
while((len = in.read(b))!=-1){
out.write(b, 0, len);
}
out.flush();
out.close();
in.close();
}

Released two original articles · won praise 0 · Views 267

Guess you like

Origin blog.csdn.net/weixin_43682921/article/details/94637150