环境:MyEclipse 10 版本

Spring框架的使用:

1.建立WEB Project 项目;

2.通过Myeclipse 10 导入Spring框架:

  这个步骤需要把Spring 相关的 JAR 包勾选上,并且将配置文件放在WEB-INF目录下,命名为 dispatcherServlet-servlet.xml;

Myeclipse 10 环境下 Spring 框架的使用

为了以后的方便,这里九江spring 的配置文件命名为了dispatcherServlet-servlet.xml,这个配置文件的名称中的前半部分是在web.xml中声明的servlet的名称

 

3.编写所需要的接口(一般需要),并实现,并用spring框架的注解进行关联:

Myeclipse 10 环境下 Spring 框架的使用Myeclipse 10 环境下 Spring 框架的使用 

接口实现时,一定添加上 @Service ,这样就能在使用接口时,自动将接口实现注入到接口中,方便快捷。

 

4.编写spring 的 controller

Myeclipse 10 环境下 Spring 框架的使用

 

5.重点编写 spring 的配置文件

Myeclipse 10 环境下 Spring 框架的使用

 

配置文件可能需要在头部加上context 和 mvc 的相应链接

同时,需要controller 组件的包名写进来,需要设置支持注解,

最后,还需要对controller的结果进行修饰(前缀+后缀)

 

6. 按照配置文件中的前缀和后缀,建立相应的目录,并建立相应的结果文件

Myeclipse 10 环境下 Spring 框架的使用

 

 

7. 对编写的controller 进行测试(在浏览器中输入相应的 controller 地址进行测试即可)

Myeclipse 10 环境下 Spring 框架的使用

 

相关文章:

  • 2021-04-20
  • 2021-09-17
  • 2021-12-01
  • 2021-04-15
  • 2021-08-07
  • 2021-07-05
  • 2022-01-13
  • 2022-12-23
猜你喜欢
  • 2021-05-01
  • 2022-02-01
  • 2022-12-23
  • 2021-05-08
  • 2021-05-19
  • 2021-04-14
相关资源
相似解决方案