JAVA 静态(static)方法中依赖注入调用Service层(Dao层)

package com.coboriel.doorlook.utils;

import com.xxx.demo.entity.HotelUser;
import com.xxx.demo.mapper.HotelUserMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class GetPayload {
    private static final Logger log = LoggerFactory.getLogger(GetPayload.class);

    @Autowired
    private HotelUserMapper hotelUserMapper;

    public static GetPayload getPayload;

    @PostConstruct
    public void init(){
        getPayload = this;
        getPayload.hotelUserMapper = this.hotelUserMapper;
    }


    public static String testPost(String mobile) {

        HotelUser hotelUser = getPayload.hotelUserMapper.getAllByMobile(mobile);

    }

}

你可能感兴趣的:(java)