package com.ruixin.controller; import com.ruixin.bean.News; import com.ruixin.bean.Type; import com.ruixin.common.entity.Page; import com.ruixin.common.utils.Views; import com.ruixin.service.LinkService; import com.ruixin.service.NewsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; /** * 前台管理类 */ @Controller public class IndexController { @Autowired private NewsService newsService; @Autowired private LinkService linkService; /** * 跳转到首页 * @param model * @param page * @return */ @GetMapping({"/","/index"}) public String index(Model model, Page<News> page){ model.addAttribute("typeList",newsService.findTypeList()); Page<News> page1=newsService.findPageList(page,new News()); model.addAttribute("page",page1); model.addAttribute("links",linkService.findList(null)); return Views.INDEX; } /** * 跳转到二级页面 * @param model * @return */ @GetMapping("/second/{typeId}") public String second(Model model,@PathVariable("typeId")Integer typeId,Page<News> page){ News news=new News(); news.setTypeId(typeId); model.addAttribute("typeList",newsService.findTypeList()); model.addAttribute("typeId",typeId); model.addAttribute("page",newsService.findPageList(page,news)); return Views.SECOND; } /** * 跳转到三级页面 * @param model * @param id * @return */ @GetMapping("/third/{id}") public String third(Model model, @PathVariable("id")int id){ model.addAttribute("typeList",newsService.findTypeList()); News news=newsService.get(id); model.addAttribute("news",news); news.setRead(String.valueOf(Integer.parseInt(news.getRead())+1)); newsService.save(news); return Views.THIRD; } /** * 关于我 */ @GetMapping("/about") public String about(Model model){ model.addAttribute("typeList",newsService.findTypeList()); return Views.ABOUT; } }