@Controller
@RequestMapping("/admin/tags")
public class TagController {
@Autowired
private ITagService tagService;
@GetMapping
public String findTags(@PageableDefault(size = 5,sort ={"id"},direction = Sort.Direction.DESC) Pageable pageable, Model model){
Page<Tag> page=tagService.listTag(pageable);
model.addAttribute("page",page);
return "admin/tags";
}
@GetMapping("/{id}/delete")
public String delete(@PathVariable Long id){
tagService.deleteTagById(id);
return "redirect:/admin/tags";
}
@GetMapping("/input")
public String input(){
return "admin/tags-input";
}
@PostMapping("/add")
public String add(Tag tag){
tagService.addTag(tag);
return "redirect:/admin/tags";
}
@GetMapping("/{id}/toUpdate")
public String toUpdate(@PathVariable Long id, Model model){
Tag tag=tagService.getTag(id);
model.addAttribute("type",tag);
return "admin/tags-input";
}
@PostMapping("/update/{id}")
public String update(Tag tag,@PathVariable Long id){
tagService.update(id,tag);
return "redirect:/admin/tags";
}
}
@Controller
@RequestMapping("/admin/blogs")
public class BlogController {
@Autowired
private IBlogService blogService;
@RequestMapping
public String blogs(@PageableDefault(size=5,sort={"updateTime"},direction = Sort.Direction.DESC) Pageable pageable, Model model){
Page<Blog> page=blogService.listBlog(pageable);
model.addAttribute("page",page);
return "admin/blogs";
}
}
@Service
public class TagServiceImpl implements ITagService {
@Autowired
private TagDao tagDao;
@Override
public Page<Tag> listTag(Pageable pageable) {
Page<Tag> page=tagDao.findAll(pageable);
return page;
}
@Override
public void deleteTagById(Long id) {
tagDao.deleteById(id);
}
@Override
public Tag getTag(Long id) {
return tagDao.getOne(id);
}
@Override
public void update(Long id, Tag tag) {
Tag tag1=tagDao.getOne(id);
BeanUtils.copyProperties(tag,tag1);
tagDao.save(tag1);
}
@Override
public void addTag(Tag tag) {
tagDao.save(tag);
}
}
@Service
public class BlogServiceImpl implements IBlogService {
@Autowired
private BlogDao blogDao;
@Override
public Page<Blog> listBlog(Pageable pageable) {
return blogDao.findAll(pageable);
}
}