ShyLogController.java 1.94 KB
package com.cnlive.shenhe.controller;

import com.alibaba.fastjson.JSON;
import com.cnlive.shenhe.bean.ErrorEnum;
import com.cnlive.shenhe.bean.ResponseBean;
import com.cnlive.shenhe.dto.ShyLogDTO;
import com.cnlive.shenhe.entity.ShyLog;
import com.cnlive.shenhe.serviceImpl.ShyLogServiceImpl;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 王言钊
 * @author shkstart
 * @create 2022-05-16 11:36
 */
@Controller
@RequestMapping("/log")
public class ShyLogController {
    private static Logger logger = LoggerFactory.getLogger(ShyLogController.class);

    @Autowired
    private ShyLogServiceImpl shyLogServiceImpl;


    @GetMapping("/page")
    public String getShyLog(ShyLogDTO shyLogDTO, Model model) {
        logger.info("进入查询日志方法,接受的对象为,ShyLogDTO:{}", JSON.toJSONString(shyLogDTO));
        PageInfo<ShyLog> shyLogPageInfo = shyLogServiceImpl.selectByExample(shyLogDTO);
        model.addAttribute("shyLogPageInfo", shyLogPageInfo);
        return "page/log.html";
    }

    @PostMapping("/add")
    @ResponseBody
    public ResponseBean insterShyLog(ShyLog shyLog) {
        logger.info("访问了日志添加方法,接受的对象为,ShyLog:{}",JSON.toJSONString(shyLog));
        int result = shyLogServiceImpl.addShyLog(shyLog);
        if (result > 0) {
            return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "当前日志添加成功");
        }
        return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "日志添加失败,请重试");
    }
}