-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from cheng521521/main
feat:1. 招聘创建 会重复创建,每次返回id都是0
- Loading branch information
Showing
9 changed files
with
185 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.dl.officialsite.hiring; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* @ClassName SponsorVo | ||
* @Author jackchen | ||
* @Date 2023/12/11 21:16 | ||
* @Description 广告 | ||
**/ | ||
@Data | ||
public class SponsorVo { | ||
|
||
private String company; | ||
|
||
private String link; | ||
|
||
private String icon; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.dl.officialsite.hiring.vo; | ||
|
||
import lombok.Data; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
/** | ||
* @ClassName ApplyVo | ||
* @Author jackchen | ||
* @Date 2023/12/11 21:45 | ||
* @Description TODO | ||
**/ | ||
@Data | ||
public class ApplyVo { | ||
|
||
private Long hireId; | ||
|
||
private MultipartFile file; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
package com.dl.officialsite.mail; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
import javax.activation.DataHandler; | ||
import javax.activation.DataSource; | ||
import javax.activation.FileDataSource; | ||
import javax.mail.internet.InternetAddress; | ||
import javax.mail.internet.MimeBodyPart; | ||
import javax.mail.internet.MimeMessage; | ||
import javax.mail.internet.MimeMultipart; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.mail.SimpleMailMessage; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
|
||
@Component | ||
|
@@ -50,4 +59,59 @@ public void sendMail(String to, String subject, String text) { | |
emailSender.send(message); | ||
} | ||
|
||
public void sendMailWithFile(String to, String subject, String text, MultipartFile file) | ||
throws Exception { | ||
//1.创建一封邮件的实例对象 | ||
MimeMessage msg = emailSender.createMimeMessage(); | ||
//2.设置发件人地址 | ||
msg.setFrom("[email protected]"); | ||
msg.setRecipient(MimeMessage.RecipientType.TO,new InternetAddress(to)); | ||
//4.设置邮件主题 | ||
msg.setSubject(subject); | ||
|
||
//下面是设置邮件正文 | ||
//msg.setContent("简单的纯文本邮件!", "text/html;charset=UTF-8"); | ||
|
||
// 9. 创建附件"节点" | ||
MimeBodyPart attachment = new MimeBodyPart(); | ||
// 读取本地文件 | ||
//mutilpart to file | ||
|
||
DataSource ds2 = new FileDataSource(MultipartFileToFile(file)); | ||
DataHandler dh2 = new DataHandler(ds2); | ||
// 将附件数据添加到"节点" | ||
attachment.setDataHandler(dh2); | ||
// 设置附件的文件名(需要编码) | ||
attachment.setFileName(file.getName()); | ||
|
||
// 10. 设置(文本+图片)和 附件 的关系(合成一个大的混合"节点" / Multipart ) | ||
MimeMultipart mm = new MimeMultipart(); | ||
mm.addBodyPart(attachment); // 如果有多个附件,可以创建多个多次添加 | ||
mm.setSubType("mixed"); // 混合关系 | ||
|
||
// 11. 设置整个邮件的关系(将最终的混合"节点"作为邮件的内容添加到邮件对象) | ||
msg.setContent(mm); | ||
|
||
emailSender.send(msg); | ||
} | ||
|
||
//将MultipartFile转换为File | ||
public static File MultipartFileToFile(MultipartFile multiFile) { | ||
// 获取文件名 | ||
String fileName = multiFile.getOriginalFilename(); | ||
if (fileName == null){ | ||
return null; | ||
} | ||
// 获取文件后缀 | ||
String prefix = fileName.substring(fileName.lastIndexOf(".")); | ||
// 若须要防止生成的临时文件重复,能够在文件名后添加随机码 | ||
try { | ||
File file = File.createTempFile(fileName, prefix); | ||
multiFile.transferTo(file); | ||
return file; | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
} |