Servlet

    1. public class BusinessAServlet extends HttpServlet {
    2. //servlet拥有接口类型的businessA属性,具体实现由实现类来处理,如果想更换实现类,改这一行就可以啦
    3. private BusinessAServiceInterface businessA = new BusinessAServiceImpl();
    4. @Override
    5. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    6. //业务逻辑处理
    7. businessA.businessAServiceTest1();
    8. businessA.businessAServiceTest2();
    9. businessA.businessAServiceTest3();
    10. }
    11. }

    service 层
    具体业务接口层

    1. public interface BusinessAServiceInterface {
    2. public abstract void businessAServiceTest1();
    3. public abstract void businessAServiceTest2();
    4. public abstract void businessAServiceTest3();
    5. }

    具体业务实现层

    1. public class BusinessAServiceImpl implements BusinessAServiceInterface{
    2. //拥有接口类型的Dao,如果以后想更换实现类,改这一行就可以了
    3. private BusinessADaoInterface businessADaoInterface = new BusinessADaoImpl();
    4. @Override
    5. public void businessAServiceTest1() {
    6. System.out.println("businessAServiceTest1");
    7. //Dao删除数据
    8. businessADaoInterface.delete(1);
    9. }
    10. @Override
    11. public void businessAServiceTest2() {
    12. System.out.println("businessAServiceTest2");
    13. }
    14. @Override
    15. public void businessAServiceTest3() {
    16. System.out.println("businessAServiceTest3");
    17. }
    18. }

    Dao层
    具体Dao接口层

    1. public interface BusinessADaoInterface {
    2. public abstract Object get(Integer id);
    3. public abstract void delete(Integer id);
    4. }

    具体Dao实现层

    1. public class BusinessADaoImpl implements BusinessADaoInterface {
    2. @Override
    3. public Object get(Integer id) {
    4. return null;
    5. }
    6. @Override
    7. public void delete(Integer id) {
    8. }
    9. }