//GirlService
package com.ljc.girl.service;
import com.ljc.girl.domain.Girl;
import com.ljc.girl.repository.GirlRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
@Service
public class GirlService {
@Autowired
private GirlRepository girlRepository;
@Transactional
public void insertTwo(){
Girl girlA=new Girl();
girlA.setCupSize("A");
girlA.setAge(18);
girlRepository.save(girlA);
Girl girlB=new Girl();
girlB.setCupSize("BBBBBBB");
girlB.setAge(19);
girlRepository.save(girlB);
}
public void getAge(Integer id) throws Exception{
Girl girl = girlRepository.findById(id);//此句报红
Integer age= girl.getAge();
if(age<10){
//返回"你还在上小学吧!"
throw new Exception("你还在上小学吧");
}else if (age>10 && age<16){
//返回“你可能在上初中”
throw new Exception("你可能在上初中");
}
}
}