发表于: 2021-01-16 23:46:45
1 1285
今天完成的事情:
继续编写Controller
明天计划的事情:
继续编写剩下的Controller,模块管理,工作室管理,一级标题,二级标题
遇到的问题:
暂无
收获:
留言管理-Controller
@Controller
@RequestMapping("/message")
public class MessageController {
@Autowired
MessageService messageService;
private static final Logger log= LogManager.getLogger(BannerController.class);
/**
* 查询留言列表(默认精选)
* @param modelAndView
* @return
*/
@RequestMapping(value = "/list",method = RequestMethod.GET)
public ModelAndView getBannerList(ModelAndView modelAndView){
List<Message> messageList=messageService.selectAllMessage();
log.info(messageList);
if (messageList!=null){
modelAndView.addObject("code",200);
modelAndView.addObject("msg","查询成功");
modelAndView.addObject("messageList",messageList);
}else {
modelAndView.addObject("code",404);
modelAndView.addObject("msg","操作失败");
}
modelAndView.setViewName("messageJson2");
return modelAndView;
}
/**
* 根据id删除单条留言
* @param id
* @param modelAndView
* @return
*/
@RequestMapping(value = "deleteMessage/id={id}",method = RequestMethod.POST)
public ModelAndView deleteBanner(@PathVariable Long id, ModelAndView modelAndView){
if(messageService.deleteByPrimaryKey(id)) {
modelAndView.addObject("code", 200);
modelAndView.addObject("msg", "删除成功");
}else {
modelAndView.addObject("code", 404);
modelAndView.addObject("msg", "操作失败");
}
modelAndView.setViewName("json");
return modelAndView;
}
/**
* 查询单条留言
* @param id
* @param modelAndView
* @return
*/
@RequestMapping(value = "/selectMessage?id={id}",method = RequestMethod.GET)
public ModelAndView getBanner(@PathVariable Long id, ModelAndView modelAndView){
Message message=messageService.selectByPrimaryKey(id);
if (message!=null){
modelAndView.addObject("code",200);
modelAndView.addObject("msg","查询成功");
modelAndView.addObject("message",message);
}else {
modelAndView.addObject("code",404);
modelAndView.addObject("msg","操作失败");
}
modelAndView.setViewName("messageJson1");
return modelAndView;
}
/**
* 设为精选留言
* @param message
* @param modelAndView
* @return
*/
@RequestMapping(value = "updateBannerSetting",method = RequestMethod.PUT)
public ModelAndView updateBannerSetting(Message message,ModelAndView modelAndView){
if(messageService.updateByPrimaryKeySetting(message)){
message.setStatus(0);
modelAndView.addObject("code",200);
modelAndView.addObject("msg","设为精选留言成功");
}else {
modelAndView.addObject("code",404);
modelAndView.addObject("msg","操作失败");
}
modelAndView.setViewName("json");
return modelAndView;
}
/**
* 取消精选留言
* @param message
* @param modelAndView
* @return
*/
@RequestMapping(value = "updateBannerCancel",method = RequestMethod.PUT)
public ModelAndView updateBannerCancel(Message message,ModelAndView modelAndView){
if(messageService.updateByPrimaryKeyCancel(message)){
message.setStatus(1);
modelAndView.addObject("code",200);
modelAndView.addObject("msg","取消精选留言成功");
}else {
modelAndView.addObject("code",404);
modelAndView.addObject("msg","操作失败");
}
modelAndView.setViewName("json");
return modelAndView;
}
/**
* 添加留言
* @param message
* @param modelAndView
* @return
*/
@RequestMapping(value ="addMessage",method = RequestMethod.POST)
public ModelAndView addMessage(Message message, ModelAndView modelAndView){
log.info(message);
if (messageService.insert(message)){
modelAndView.addObject("code",200);
modelAndView.addObject("msg","添加成功");
}else {
modelAndView.addObject("code",404);
modelAndView.addObject("msg","操作失败");
}
modelAndView.setViewName("json");
return modelAndView;
}
/**
* 回复留言
* @param message
* @param modelAndView
* @return
*/
@RequestMapping(value = "addReply",method = RequestMethod.PUT)
public ModelAndView addReply(Message message,ModelAndView modelAndView){
if(messageService.addReply(message)){
modelAndView.addObject("code",200);
modelAndView.addObject("msg","保存成功");
}else {
modelAndView.addObject("code",404);
modelAndView.addObject("msg","保存失败");
}
modelAndView.setViewName("json");
return modelAndView;
}
}
==================
测试:
评论