标签:java基础
class Student {
private List<Course> courses;
}
class Course {
}
public class EmpServiceImpl implements EmpService{
@Resource
EmpMapper empMapper;
@Override
public int save(Emp emp) {
return empMapper.save(emp);
}
}
public void query(){
Emp emp = new Emp();
}
public Emp getById(Integer empno) {
return empMapper.getById(empno);
}
public Integer removeBatch(Collection<Integer> empnos){
if (!CollectionUtils.isEmpty(empnos)) {
return empMapper.removeBatch(empnos);
}
return 0;
}
public class EmpServiceImpl implements EmpService{
@Resource
EmpMapper empMapper;
}
聚合关系表示整体与部分的关系,是一种弱的拥有关系。一个对象可以包含另一个对象,但它们的生命周期可以独立存在。聚合关系通常用成员变量表示。
class Book {
private String title;
public Book(String title) {
this.title = title;
}
public String getTitle() {
return title;
}
}
class Library {
private List<Book> books;
public Library() {
this.books = new ArrayList<>();
}
public void addBook(Book book) {
books.add(book);
}
public List<Book> getBooks() {
return books;
}
}
组合关系表示整体与部分的关系,是一种强的拥有关系。整体对象负责管理部分对象的生命周期。组合关系通常也用成员变量表示。
class Wheel {
private String position; // 前左、前右、后左、后右等
public Wheel(String position) {
this.position = position;
}
public String getPosition() {
return position;
}
}
class Car {
private List<Wheel> wheels = new ArrayList<>();
public Car() {
// 添加四个轮子到汽车
wheels.add(new Wheel("Front Left"));
wheels.add(new Wheel("Front Right"));
wheels.add(new Wheel("Rear Left"));
wheels.add(new Wheel("Rear Right"));
}
// 获取汽车的所有轮子
public List<Wheel> getWheels() {
return wheels;
}
}