pojo
public class User {
private int userid;
public User(int userid) {this.userid = userid;}
public User() {}
public int getUserid() {return userid;}
public void setUserid(int userid) {this.userid = userid;}
}
controller
@Controller
@RequestMapping
@ResponseBody
public class FindByIdController {
@Autowired
private FindByIdService findByIdService;
@GetMapping("/practice/{userid}")
public List<User> findById(@PathVariable int userid) {
List<User> userids = findByIdService.findById(userid);
return userids;
}
}
service
public interface FindByIdService {
List<User> findById(int userid);
}
serviceImpl
package com.example.demo.service.impl;
import com.example.demo.mapper.FindByIdMapper;
import com.example.demo.pojo.User;
import com.example.demo.service.FindByIdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class FindByIdImpl implements FindByIdService {
@Autowired
private FindByIdMapper findByIdMapper;
@Override
public List<User> findById(int userid) {
List<Integer> userIds = findByIdMapper.findById(userid);
List<User> users = new ArrayList<>();
for (Integer userId : userIds) {
User user = new User();
user.setUserid(userId);
users.add(user);
}
return users;
}
}
mapper
@Mapper
public interface FindByIdMapper {
@Select("select userid from orguser where departmentid = #{userid}")
List<Integer> findById(@Param("userid") int userid);
}
标签:SpringBoot,一个,List,userid,案例,int,User,import,public
From: https://www.cnblogs.com/lmcool/p/17757107.html