以我的项目中的,StudentService类为例,调用StudentMapper接口

在StudentService,应这样写

package com.group.oybk.demo.service;

import com.group.oybk.demo.common.domain.Student;
import com.group.oybk.demo.dao.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("all")
@Service

public class StudentService {
    @Autowired
    StudentMapper studentDao;

    public static StudentService studentService;
    @PostConstruct
    public void init(){
        studentService=this;
        studentService.studentDao=this.studentDao;
    }
    public List<Student> testSelectByIds(){
        List<Integer> ids = new ArrayList<>();
        ids.add(7);
        ids.add(8);
        ids.add(11);
        List<Student> students = studentService.studentDao.selectBatchIds(ids);
        for (Student stu:students) {
            System.out.println(stu);
        }
        return students;
    }
}
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐