目录
一:多张数据表写入同一个实体类
现在有两张表。一张student表,一张class表


实体类
@Data
public class ClassAndStudent {
private int cid;
private String course;
private int tid;
//以上为class表数据,以下为Student表数据
private int sid;
private String sname;
private String sbirth;
private String sgender;
}
Dao层
@Repository
public interface UseXmlDao {
List<ClassAndStudent> findAll();
}
Service层
//接口层
@Service
public interface UserService {
List<ClassAndStudent> findAll();
}
//实现接口层
@Service
public class UserServiceImp implements UserService {
@Autowired
private UseXmlDao useXmlDao;
@Override
public List<ClassAndStudent> findAll() {
return useXmlDao.findAll();
}
Controller层
@RestController
public class UserController {
@Autowired
private UserService userService;
@RequestMapping ("/duobiao")
public @ResponseBody List<ClassAndStudent> findAll(){
List<ClassAndStudent> classAndStudentList = userService.findAll();
return classAndStudentList;
}
}
XML
<select id="findAll" resultType="com.xiaosuda.boot.Pojo.ClassAndStudent" >
select * from student,class
</select><

最低0.47元/天 解锁文章
5047

被折叠的 条评论
为什么被折叠?



