caontroller层
/**
* @author xu
* @date:2022/3/2718:27
*/
@RequestMapping("/video")
@RestController
public class VedioController {
// @Resource(name= "videoServiceImpl")
@Autowired
private VideoService videoService;
@RequestMapping("/list")
@LogAnnotation(module = "视频",operation = "获取视频列表")
private Result getVedioList(@RequestBody QueryParams queryParams){
DataVo vedioList = videoService.getVedioList(queryParams);
return Result.success(vedioList);
}
@RequestMapping("/add")
@LogAnnotation(module = "视频",operation = "获取视频列表")
private Result addVeedio(@RequestBody VideoParams videoParams){
Result result = videoService.addVedio(videoParams);
return Result.success(result);
}
@RequestMapping("/del")
@LogAnnotation(module = "视频",operation = "获取视频列表")
private Result delVedio(@RequestParam Integer id){
videoService.delVedio(id);
return Result.success(null);
}
@RequestMapping("/edit")
@LogAnnotation(module = "视频",operation = "获取视频列表")
private Result editVedio(@RequestBody VideoParams videoParams){
return Result.success(videoService.editVedio(videoParams));
}
}
service层
@Service
@Transactional
public class VideoServiceImpl implements VideoService {
@Autowired
private VideoMapper videoMapper;
@Autowired
private TeacherService teacherService;
@Autowired
private DataVo dataVo;
@Override
public DataVo getVedioList(QueryParams queryParams) {
Page<Video> page = new Page<>(queryParams.getCurrentPage(), queryParams.getPageSize());
QueryWrapper<Video> queryWrapper = new QueryWrapper<>();
queryWrapper.orderByDesc("id");
Page<Video> vedioPage = videoMapper.selectPage(page,queryWrapper);
List<VideoParams> videoParamsList = copyVedioList(vedioPage.getRecords());
// DataVo dataVo = new DataVo(videoParamsList, Math.toIntExact(vedioPage.getTotal()));
dataVo.setList(videoParamsList);
dataVo.setTotal(Math.toIntExact(vedioPage.getTotal()));
return dataVo;
}
private List<VideoParams> copyVedioList(List<Video> videoList){
List<VideoParams> videoParamsList = new ArrayList<>();
for (Video video : videoList) {
videoParamsList.add(copyVedio(video));
}
return videoParamsList;
}
private VideoParams copyVedio(Video video){
VideoParams videoParams = new VideoParams();
BeanUtils.copyProperties(video, videoParams);
Teacher teacher= teacherService.findTeacherById(video.getUserId());
videoParams.setCreateName(teacher.getName());
return videoParams;
}
@Override
public Result editVedio(VideoParams videoParams) {
// User user = UserThreadLocal.get();
// vedioParams.setUserId(user.getId());
Video video = new Video();
BeanUtils.copyProperties(videoParams, video);
videoMapper.updateById(video);
return Result.success(null);
}
@Override
public Result addVedio(VideoParams videoParams) {
// User user = UserThreadLocal.get();
// vedioParams.setUserId(user.getId());
Video video = new Video();
BeanUtils.copyProperties(videoParams, video);
videoMapper.insert(video);
return Result.success(null);
}
@Override
public void delVedio(Integer id) {
videoMapper.deleteById(id);
}
}
这个是打印spring里面的bean名称,红框中的bean就是注入不进去的bean
最后问题发现是因为controller中的方法都是private,然后就改成public就没有问题了
最后把打印bean的代码
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
};
}