package org.example.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.example.common.ServerResponse; import org.example.dao.JournalismMapper; import org.example.pojo.Journalism; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * @program: webSocketProject * @description: 新闻 * @create: 2024-03-27 14:03 **/ @RestController @RequestMapping("/api/news/") public class JournalismController { @Autowired JournalismMapper journalismMapper; @GetMapping("getNewsListAll.do") public ServerResponse JournalismAll(){ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); return ServerResponse.createBySuccess(journalismMapper.selectList(queryWrapper)); } @GetMapping("getNewsList.do") public ServerResponse JournalismNumber(){ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.orderByDesc(Journalism::getTime).last("limit 20"); return ServerResponse.createBySuccess(journalismMapper.selectList(queryWrapper)); } }