Springboot普通类调用mapper

2022-06-29 09:39:43
@RequestMapping("")
@MapperScan("com.jatham.cloud.platform.mapper")
@Component
public class H2Client{
    //注入mappper
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private DataNodeMapper dataNodeMapper;
    public  static H2Client h2Client;

    @PostConstruct
    public voidinit(){
        h2Client= this;
        h2Client.dataNodeMapper= this.dataNodeMapper;}

需要注解
@Component
@Autowired 自动装配
@PostConstruct
被@PostConstruct修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器调用一次,类似于Serclet的inti()方法。被@PostConstruct修饰的方法会在构造函数之后,init()方法之前运行。

  • 作者:Jatham_C
  • 原文链接:https://blog.csdn.net/qq_42784606/article/details/102929293
    更新时间:2022-06-29 09:39:43