原始Spring Java配置类 实现MVC

是Spring4.x推荐的配置方式 但我觉得一点用都没。大概逻辑如下 :

原始Spring Java配置类 实现MVC

 

 

原始Spring Java配置类 实现MVC
package com.bihu.conno.helloDao;

public interface HelloDao {
    void show();
}
HelloDao 原始Spring Java配置类 实现MVC
package com.bihu.conno.helloDaoImpl;


import com.bihu.conno.helloDao.HelloDao;

public class HelloDaoImpl implements HelloDao {
    public HelloDaoImpl() {
    }

    @Override
    public void show() {
        System.out.println("Dao -- Show");
    }
}
HelloDaoImpl 原始Spring Java配置类 实现MVC
package com.bihu.conno.helloService;

public interface HelloService {
    void show();
}
HelloService 原始Spring Java配置类 实现MVC
package com.bihu.conno.HelloServiceImpl;

import com.bihu.conno.helloDao.HelloDao;
import com.bihu.conno.helloService.HelloService;

public class HelloServiceImpl implements HelloService {
    //HelloDao
    HelloDao dao;

    //构造
    public HelloServiceImpl(HelloDao helloDao) {
        this.dao = helloDao;
    }

    @Override
    public void show() {
        dao.show(); //调用Dao的Show
        System.out.println("Service -- Show");
    }
}
HelloServiceImpl 原始Spring Java配置类 实现MVC
package com.bihu.conno.Controller;

import com.bihu.conno.helloService.HelloService;

public class HelloController {
    //HelloService
    HelloService service;

    //构造
    public HelloController(HelloService service) {
        this.service = service;
    }

    public  void show() {
        service.show();
    }

}
HelloController 原始Spring Java配置类 实现MVC
package com.bihu.conno;


import com.bihu.conno.Controller.HelloController;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Test {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext app = new AnnotationConfigApplicationContext(Config.class);
        HelloController bean = app.getBean(HelloController.class);
        bean.show();
    }
}
Config配置类 原始Spring Java配置类 实现MVC
package com.bihu.conno;


import com.bihu.conno.Controller.HelloController;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Test {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext app = new AnnotationConfigApplicationContext(Config.class);
        HelloController bean = app.getBean(HelloController.class);
        bean.show();
    }
}
Test测试类

 

运行:

原始Spring Java配置类 实现MVC

 

上一篇:C语言 导出函数的格式


下一篇:CSS常见问题