系统公告信息功能 参考代码

pojo

import lombok.AllArgsConstructor;

import lombok.Data;

import lombok.NoArgsConstructor;

@Data

@NoArgsConstructor

@AllArgsConstructor

public class Announcement extends BasePojo {

private Long id;

private String title;

private String description;

}

======================================================================

AnnouncementMapper

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.tanhua.common.pojo.Announcement;

public interface AnnouncementMapper extends BaseMapper {

}

===============================================================

AnnouncementService

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.tanhua.common.mapper.AnnouncementMapper;

import com.tanhua.common.pojo.Announcement;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

@Service

public class AnnouncementService {

@Autowired

private AnnouncementMapper announcementMapper;

public IPage queryList(Integer page, Integer pageSize) {

QueryWrapper queryWrapper = new QueryWrapper();

queryWrapper.orderByDesc(“created”);

return this.announcementMapper.selectPage(new Page(page, pageSize), queryWrapper);

}

}

===================================================================

app 实体对象

import lombok.AllArgsConstructor;

import lombok.Data;

import lombok.NoArgsConstructor;

@Data

@NoArgsConstructor

@AllArgsConstructor

public class AnnouncementVo {

private String id;

private String title;

private String description;

private String createDate;

}

=============================================================

controller

/**

* 查询公告列表

*

* @param page

* @param pageSize

* @return

*/

@GetMapping(“announcements”)

@NoAuthorization //优化,无需进行token校验

public ResponseEntity queryMessageAnnouncementList(@RequestParam(value = “page”, defaultValue = “1”) Integer page,

@RequestParam(value = “pagesize”, defaultValue = “10”) Integer pageSize) {

try {

PageResult pageResult = this.imService.queryMessageAnnouncementList(page, pageSize);

return ResponseEntity.ok(pageResult);

} catch (Exception e) {

log.error(“查询公告列表失败~ “, e);

}

return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();

}

================================================================

service

public PageResult queryMessageAnnouncementList(Integer page, Integer pageSize) {

IPage announcementPage = this.announcementService.queryList(page, pageSize);

List announcementVoList = new ArrayList();

for (Announcement record : announcementPage.getRecords()) {

AnnouncementVo announcementVo = new AnnouncementVo();

announcementVo.setId(record.getId().toString());

announcementVo.setTitle(record.getTitle());

announcementVo.setDescription(record.getDescription());

announcementVo.setCreateDate(DateUtil.format(record.getCreated(), “yyyy-MM-dd HH:mm”));

announcementVoList.add(announcementVo);

}

PageResult pageResult = new PageResult();

pageResult.setPage(page);

pageResult.setPagesize(pageSize);

pageResult.setItems(announcementVoList);

return pageResult;

}

郑重声明:本文内容及图片均整理自互联网,不代表本站立场,版权归原作者所有,如有侵权请联系管理员(admin#wlmqw.com)删除。
上一篇 2022年6月18日 12:05
下一篇 2022年6月18日 12:05

相关推荐

联系我们

联系邮箱:admin#wlmqw.com
工作时间:周一至周五,10:30-18:30,节假日休息