spring MVC和hibernate的结合

我们在没有用注解写spring配置文件的时候:会在spring配置文件中定义Dao层的bean,这样我们在service层中,写setDao方法,就可以直接通过接口调用Dao层。
                                  用了注解写法后: 在配置文件中不用再写Dao层的bean。


只需要在Dao实现类中加入
@Repository
public Class TestDaoImpl(){}

在service层定义
@Autowired
private TestDao testDao;
不需要再写setDao方法就可以通过接口调用Dao了

在Service层加入
@service
public Class TestService(){}
这样action中直接写
@Autowired
private TestService testService;
就可以调用service层

在Action层加入
@Controller
public Class TestAction(){}
就不需要在配置文件中定义action的bean

@requestMapping是spring-mvc的东西,
以前我们用struts2, 需要配置文件定义 action的名字,
在浏览器中写 XXX.do才能访问action的方法

使用了srping-mvc后,在action的方法中加入
@controller
public class TestAction(){
     @requestMapping("XXX.do")
     public String findAll(){
        .................   
    }
}
这样,就不需要struts了,直接在浏览器中输入XXX.do就可以访问findAll方法了

原文地址:https://www.cnblogs.com/adrianlamo/p/3597942.html