Spring 模拟管理Web应用程序

MVC:Model View Controller

        1)controller:控制层(Servlet是运行服务器端,处理请求响应java语言编写技术)

        2)service:业务层(事务,异常)

        3)dao:持久层(CRUD)

Spring :IOC 和 DI

准备工作

在java文件夹的com.xja下创建

Dao包:

       StudentDao.java

        StudentDaoImpl.java

Service包:

        StudentService.java

        StudentServiceImpl.java

Controller包:

        StudentController.java

        StudentControllerImpl.java

在Spring的配置文件中添加相应实体类的注入

自动装配(autowire):

                1.按名称;byName

                         只要对象对应属性名与xml中实例化对象id一致可以实现自动装配

                2.按照类型;byType  

                        只要对象对应属性类型与xml中实例化对象类型一致可以实现自动装配

                3.constructor

                默认不会自动装配

<bean id="studentController" class="com.xja.controller.StudentController" autowire="byName">         

             //  等价于   <property name="studentService" ref="studnetService"/>

</bean>

<bean id="studentService" class="com.xja.service.impl.StudentServiceImpl" autowire="constructor">

            //   等价于  <constructor-arg name="studentDao" ref="studnetDao"/>

</bean>                        

<bean id="studentDao" class="com.xja.dao.impl.StudentDaoImpl" /> 

全局设置autowire:

注意:byType方式自动装配:

        要装配的实现类实现接口,还有别的实现类也实现了接口,

        这时只能使用byName的方式实现装配。

相关推荐

  1. web应用使用spring

    2024-05-25 18:00:53       17 阅读
  2. 使用Spring Boot Admin监控和管理Spring Boot应用程序

    2024-05-25 18:00:53       16 阅读
  3. RESTful API构建 web 应用程序

    2024-05-25 18:00:53       15 阅读
  4. RESTful API 构建 Web 应用程序

    2024-05-25 18:00:53       9 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-05-25 18:00:53       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-05-25 18:00:53       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-05-25 18:00:53       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-05-25 18:00:53       20 阅读

热门阅读

  1. Spring: OncePerRequestFilter

    2024-05-25 18:00:53       10 阅读
  2. 缪尔赛思又来到了你的面前(哈希)

    2024-05-25 18:00:53       10 阅读
  3. #php把pdf文件转成图片#

    2024-05-25 18:00:53       12 阅读
  4. 在已创建的git工程中添加.gitignore

    2024-05-25 18:00:53       10 阅读
  5. git忽略文件不生效解决方案

    2024-05-25 18:00:53       13 阅读
  6. git-将老项目的分支推送到新项目的新分支上

    2024-05-25 18:00:53       10 阅读
  7. ffmpeg3.1.1版本连接ftp服务器失败

    2024-05-25 18:00:53       12 阅读