东莞有哪些做网站,在家做的打字兼职的网站,做网站的电话号码,电子产品去什么网站做站点### 使用Spring Boot实现OA通知公告模块
使用Spring Boot框架实现一个支持多种形式公告发布、设置发布时间和有效期#xff0c;以及公告发布后推送通知的模块。
#### 项目结构
结构组织项目#xff1a; OA_Notification_Module/ ├── src/ │ ├── main/ │ │ …### 使用Spring Boot实现OA通知公告模块
使用Spring Boot框架实现一个支持多种形式公告发布、设置发布时间和有效期以及公告发布后推送通知的模块。
#### 项目结构
结构组织项目 OA_Notification_Module/ ├── src/ │ ├── main/ │ │ ├── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── oamodule/ │ │ │ ├── controller/ │ │ │ │ └── AnnouncementController.java │ │ │ ├── model/ │ │ │ │ └── Announcement.java │ │ │ ├── repository/ │ │ │ │ └── AnnouncementRepository.java │ │ │ ├── service/ │ │ │ │ ├── AnnouncementService.java │ │ │ │ └── NotificationService.java │ │ │ └── OaNotificationModuleApplication.java │ │ └── resources/ │ │ ├── application.properties │ └── test/ │ └── java/ └── pom.xml
#### 1. Announcement 模型类
java package com.example.oamodule.model;
import javax.persistence.Entity; import javax.persistence.Id; import java.time.LocalDateTime;
Entity public class Announcement { Id private String id; private String type; // TEXT, IMAGE, VIDEO private String content; private LocalDateTime publishTime; private LocalDateTime expiryTime; public Announcement() {} public Announcement(String id, String type, String content, LocalDateTime publishTime, LocalDateTime expiryTime) { this.id id; this.type type; this.content content; this.publishTime publishTime; this.expiryTime expiryTime; } // Getters and Setters public String getId() { return id; } public void setId(String id) { this.id id; } public String getType() { return type; } public void setType(String type) { this.type type; } public String getContent() { return content; } public void setContent(String content) { this.content content; } public LocalDateTime getPublishTime() { return publishTime; } public void setPublishTime(LocalDateTime publishTime) { this.publishTime publishTime; } public LocalDateTime getExpiryTime() { return expiryTime; } public void setExpiryTime(LocalDateTime expiryTime) { this.expiryTime expiryTime; } public boolean isExpired() { return LocalDateTime.now().isAfter(expiryTime); } }
#### 2. AnnouncementRepository 接口
java package com.example.oamodule.repository;
import com.example.oamodule.model.Announcement; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository;
import java.time.LocalDateTime; import java.util.List;
Repository public interface AnnouncementRepository extends JpaRepositoryAnnouncement, String { ListAnnouncement findByExpiryTimeAfter(LocalDateTime now); }
#### 3. AnnouncementService 服务类
java package com.example.oamodule.service;
import com.example.oamodule.model.Announcement; import com.example.oamodule.repository.AnnouncementRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;
import java.time.LocalDateTime; import java.util.List;
Service public class AnnouncementService { Autowired private AnnouncementRepository announcementRepository; public void createAnnouncement(String id, String type, String content, LocalDateTime publishTime, LocalDateTime expiryTime) { Announcement announcement new Announcement(id, type, content, publishTime, expiryTime); announcementRepository.save(announcement); System.out.println(Announcement created: announcement.getId()); } public ListAnnouncement getAllAnnouncements() { return announcementRepository.findAll(); } public ListAnnouncement getActiveAnnouncements() { return announcementRepository.findByExpiryTimeAfter(LocalDateTime.now()); } public void removeExpiredAnnouncements() { ListAnnouncement announcements announcementRepository.findAll(); for (Announcement announcement : announcements) { if (announcement.isExpired()) { announcementRepository.delete(announcement); } } } }
#### 4. NotificationService 服务类
java package com.example.oamodule.service;
import com.example.oamodule.model.Announcement; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.stereotype.Service;
import java.util.List;
Service public class NotificationService { Autowired private JavaMailSender mailSender; public void sendNotifications(ListAnnouncement announcements) { for (Announcement announcement : announcements) { // 模拟推送到电子邮件 SimpleMailMessage message new SimpleMailMessage(); message.setTo(employeeexample.com); message.setSubject(New Announcement: announcement.getType()); message.setText(announcement.getContent()); mailSender.send(message); System.out.println(Sent notification for announcement: announcement.getId()); } } }
#### 5. AnnouncementController 控制器类
java package com.example.oamodule.controller;
import com.example.oamodule.model.Announcement; import com.example.oamodule.service.AnnouncementService; import com.example.oamodule.service.NotificationService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime; import java.util.List;
RestController RequestMapping(/announcements) public class AnnouncementController { Autowired private AnnouncementService announcementService; Autowired private NotificationService notificationService; PostMapping public void createAnnouncement(RequestBody Announcement announcement) { announcementService.createAnnouncement(announcement.getId(), announcement.getType(), announcement.getContent(), announcement.getPublishTime(), announcement.getExpiryTime()); notificationService.sendNotifications(List.of(announcement)); } GetMapping public ListAnnouncement getAllAnnouncements() { return announcementService.getAllAnnouncements(); } GetMapping(/active) public ListAnnouncement getActiveAnnouncements() { return announcementService.getActiveAnnouncements(); } DeleteMapping(/expired) public void removeExpiredAnnouncements() { announcementService.removeExpiredAnnouncements(); } }
#### 6. 应用主类
java package com.example.oamodule;
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
SpringBootApplication public class OaNotificationModuleApplication { public static void main(String[] args) { SpringApplication.run(OaNotificationModuleApplication.class, args); } }
#### 7. application.properties 配置文件
properties spring.datasource.urljdbc:mysql://localhost:3306/oamodule spring.datasource.usernameroot spring.datasource.passwordpassword spring.jpa.hibernate.ddl-autoupdate
spring.mail.hostsmtp.example.com spring.mail.port587 spring.mail.usernameyour-emailexample.com spring.mail.passwordyour-email-password spring.mail.properties.mail.smtp.authtrue spring.mail.properties.mail.smtp.starttls.enabletrue
#### 8. 数据库初始化脚本
sql CREATE DATABASE oamodule;
USE oamodule;
CREATE TABLE announcements ( id VARCHAR(50) PRIMARY KEY, type VARCHAR(10), content TEXT, publish_time TIMESTAMP, expiry_time TIMESTAMP );
#### 9. pom.xml 示例
xml project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://www.apache.org/xsd/maven-4.0.0.xsd modelVersion4.0.0/modelVersion groupIdcom.example/groupId artifactIdoamodule/artifactId version1.0-SNAPSHOT/version properties java.version11/java.version /properties dependencies dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-data-jpa/artifactId /dependency dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-mail/artifactId /dependency dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-web/artifactId /dependency dependency groupIdmysql/groupId artifactIdmysql-connector-java/artifactId scoperuntime/scope /dependency dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-test/artifactId scopetest/scope /dependency /dependencies build plugins plugin groupIdorg.springframework.boot/groupId artifactIdspring-boot-maven-plugin/artifactId /plugin /plugins /build /project
使用Spring Boot框架实现了一个支持多种形式公告发布、设置发布时间和有效期以及公告发布后推送功能的OA通知公告模块。这个模块结合了JPA进行数据库操作并使用Spring Mail进行邮件推送。 文章转载自: http://www.morning.fllfc.cn.gov.cn.fllfc.cn http://www.morning.zlgr.cn.gov.cn.zlgr.cn http://www.morning.sqqdy.cn.gov.cn.sqqdy.cn http://www.morning.nshhf.cn.gov.cn.nshhf.cn http://www.morning.hryhq.cn.gov.cn.hryhq.cn http://www.morning.pqjlp.cn.gov.cn.pqjlp.cn http://www.morning.mngyb.cn.gov.cn.mngyb.cn http://www.morning.mjtft.cn.gov.cn.mjtft.cn http://www.morning.fewhope.com.gov.cn.fewhope.com http://www.morning.litao4.cn.gov.cn.litao4.cn http://www.morning.djmdk.cn.gov.cn.djmdk.cn http://www.morning.rqlzz.cn.gov.cn.rqlzz.cn http://www.morning.sqgqh.cn.gov.cn.sqgqh.cn http://www.morning.wmdbn.cn.gov.cn.wmdbn.cn http://www.morning.hrtfz.cn.gov.cn.hrtfz.cn http://www.morning.ljjph.cn.gov.cn.ljjph.cn http://www.morning.mqnbm.cn.gov.cn.mqnbm.cn http://www.morning.grpfj.cn.gov.cn.grpfj.cn http://www.morning.prgdy.cn.gov.cn.prgdy.cn http://www.morning.xyrss.cn.gov.cn.xyrss.cn http://www.morning.xxfxxf.cn.gov.cn.xxfxxf.cn http://www.morning.tgpgx.cn.gov.cn.tgpgx.cn http://www.morning.fssjw.cn.gov.cn.fssjw.cn http://www.morning.rpgdd.cn.gov.cn.rpgdd.cn http://www.morning.wbxtx.cn.gov.cn.wbxtx.cn http://www.morning.rqjxc.cn.gov.cn.rqjxc.cn http://www.morning.mbhdl.cn.gov.cn.mbhdl.cn http://www.morning.gsksm.cn.gov.cn.gsksm.cn http://www.morning.kfcz.cn.gov.cn.kfcz.cn http://www.morning.tbrnl.cn.gov.cn.tbrnl.cn http://www.morning.lywys.cn.gov.cn.lywys.cn http://www.morning.nlwrg.cn.gov.cn.nlwrg.cn http://www.morning.fksxs.cn.gov.cn.fksxs.cn http://www.morning.xkppj.cn.gov.cn.xkppj.cn http://www.morning.lsbjj.cn.gov.cn.lsbjj.cn http://www.morning.rpstb.cn.gov.cn.rpstb.cn http://www.morning.hlxxl.cn.gov.cn.hlxxl.cn http://www.morning.cknsx.cn.gov.cn.cknsx.cn http://www.morning.rhfh.cn.gov.cn.rhfh.cn http://www.morning.nlgnk.cn.gov.cn.nlgnk.cn http://www.morning.fjkkx.cn.gov.cn.fjkkx.cn http://www.morning.ppqjh.cn.gov.cn.ppqjh.cn http://www.morning.lmqfq.cn.gov.cn.lmqfq.cn http://www.morning.kztpn.cn.gov.cn.kztpn.cn http://www.morning.bnmfq.cn.gov.cn.bnmfq.cn http://www.morning.qtzqk.cn.gov.cn.qtzqk.cn http://www.morning.sgpny.cn.gov.cn.sgpny.cn http://www.morning.51meihou.cn.gov.cn.51meihou.cn http://www.morning.cffwm.cn.gov.cn.cffwm.cn http://www.morning.gcysq.cn.gov.cn.gcysq.cn http://www.morning.c7496.cn.gov.cn.c7496.cn http://www.morning.hsjrk.cn.gov.cn.hsjrk.cn http://www.morning.gpkjx.cn.gov.cn.gpkjx.cn http://www.morning.twhgn.cn.gov.cn.twhgn.cn http://www.morning.tnthd.cn.gov.cn.tnthd.cn http://www.morning.dpjtn.cn.gov.cn.dpjtn.cn http://www.morning.gqcsd.cn.gov.cn.gqcsd.cn http://www.morning.jbshh.cn.gov.cn.jbshh.cn http://www.morning.zkgpg.cn.gov.cn.zkgpg.cn http://www.morning.cbpmq.cn.gov.cn.cbpmq.cn http://www.morning.yfwygl.cn.gov.cn.yfwygl.cn http://www.morning.homayy.com.gov.cn.homayy.com http://www.morning.nnhfz.cn.gov.cn.nnhfz.cn http://www.morning.xlclj.cn.gov.cn.xlclj.cn http://www.morning.mxmzl.cn.gov.cn.mxmzl.cn http://www.morning.lrskd.cn.gov.cn.lrskd.cn http://www.morning.mkfhx.cn.gov.cn.mkfhx.cn http://www.morning.jghqc.cn.gov.cn.jghqc.cn http://www.morning.pudejun.com.gov.cn.pudejun.com http://www.morning.xcjwm.cn.gov.cn.xcjwm.cn http://www.morning.lkbdy.cn.gov.cn.lkbdy.cn http://www.morning.knsmh.cn.gov.cn.knsmh.cn http://www.morning.ljcjc.cn.gov.cn.ljcjc.cn http://www.morning.spqtq.cn.gov.cn.spqtq.cn http://www.morning.tqjks.cn.gov.cn.tqjks.cn http://www.morning.rfmzc.cn.gov.cn.rfmzc.cn http://www.morning.wsnjn.cn.gov.cn.wsnjn.cn http://www.morning.ybyln.cn.gov.cn.ybyln.cn http://www.morning.sbwr.cn.gov.cn.sbwr.cn http://www.morning.smspc.cn.gov.cn.smspc.cn