@Component->public static TestUtil testUtil->@PostConstruct->init()->testUtil.alarmLogMapper.insert();
import com.xxxx.mapper.AlarmLogMapper; import com.xxxx.mapper.DefenceMapper;; import com.xxxx.model.AlarmLog; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; //命令解码工具类 @Slf4j @Component public class TestUtil { //返回头部 @Autowired AlarmLogMapper alarmLogMapper; @Autowired DefenceMapper defenceMapper; public static TestUtil testUtil; static AlarmLog alarmLog = new AlarmLog(); @PostConstruct public void init() { testUtil = this; } //报警日志记录 public static void addAlarmLog() { alarmLog.setNickname("报警主机"); alarmLog.setUserId(9999); testUtil.alarmLogMapper.insert(alarmLog); } }