关于Spring boot 普通类如何调用Mapper类接口
以我的项目中的,StudentService类w
·
以我的项目中的,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;
}
}
更多推荐
已为社区贡献1条内容
所有评论(0)