1E)Spring MVC框架

①Jar包结构:
docs+libs+schema.
版本区别:核心包,源码包。


SpringMVC文档学习;
学习三步骤:

1)是什么?
开源框架


2)做什么?
IOC :依赖注入。是一种设计模式
set()方式注入
AOP:  
3)怎么做?

②创建一个简单的Spring框架
代码目录结构如下:

步骤:
1)创建JavaBean
2)创建Dao,和Service类
3)写好配置文件applicationContext.xml
基本的配置代码如下:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:tx="http://www.springframework.org/schema/tx"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  6. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
  7. <bean id="userBean" class="Spring_Bean.UserBean">
  8. <property name="username" value="kam"></property>
  9. <property name="password" value="123456"></property>
  10. </bean>
  11. <bean id="userDao" class="Spring_Dao.UserDaoImpl"></bean>
  12. <bean id="userService" class="Spring_Service.UserServiceImpl">
  13. <property name="daoInf" ref="userDao"></property>
  14. </bean>
  15. </beans>
③Spring其他注入方式:注解注入
1)关键字:@Resource  @Autowired(一般情况下我们用的都是Resource注解,因为这个注解不依赖与SpringMVC).
2)在日常的开发中,我们的组件类通常有几十个甚至上百个,如果我们都用<bean></bean>字段在XML文件进行声明,这种效率是及其低下的。所以我们应该使用Spring提供的组件扫描机制,只要声明了要扫描的包,Spring容器就会自动将已经用”@Controller  @Service @Repository @Component“声明的组件类归并起来。
其中 
@Service用于标注业务层的组件,@Controller用于标注控制层组件(如struts中的action),@Repository用于标注数据访问组件,即DAO组件,而@Component泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注。但是在目前的spring版本中,这几个注解的作用是一样的,但是在以后可能会进行区分。
代码如下:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. - Middle tier application context definition for the image database.
  4. -->
  5. <beans xmlns="http://www.springframework.org/schema/beans"
  6. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  7. xmlns:context="http://www.springframework.org/schema/context"
  8. xmlns:tx="http://www.springframework.org/schema/tx"
  9. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  10. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
  11. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
  12. <!-- 扫描cn.CMSystem的bean -->
  13. <context:component-scan base-package="cn.CMSystem"> </context:component-scan>
  14. </beans>








SpringMVC学习记录的更多相关文章

  1. springMVC学习记录1-使用XML进行配置

    SpringMVC是整个spring中的一个很小的组成,准确的说他是spring WEB这个模块的下一个子模块,Spring WEB中除了有springMVC还有struts2,webWork等MVC ...

  2. SpringMVC学习记录5

    Springmvc流程中的扩展点有很多,可以在很多地方插入自己的代码逻辑达到控制流程的目的. 如果要对Controller的handler方法做统一的处理.我想应该会有很多选择,比如:@ModelAt ...

  3. SpringMVC学习记录4

    主题 SpringMVC有很多很多的注解.其中有2个注解@SessionAttributes @ModelAttribute我平时一般不用,因为实在是太灵活了.但是又有一定限制,用不好容易错.. 最近 ...

  4. SpringMVC学习记录3

    这次的主题 最近一直在学习SpringMVC..(这句话我已经至少写了3,4遍了....).这次的研究主要是RequestMappingHandlerAdapter中的各种ArgumentsResol ...

  5. SpringMVC学习记录2

    废话 最近在看SpringMVC...里面东西好多...反正东看一点西看一点吧... 分享一下最近的一些心得..是关于DispatcherServlet的 DispatcherServlet与Cont ...

  6. springMVC学习记录2-使用注解配置

    前面说了一下使用xml配置springmvc,下面再说说注解配置.项目如下: 业务很简单,主页和输入用户名和密码进行登陆的页面. 看一下springmvc的配置文件: <?xml version ...

  7. SpringMVC学习记录1

    起因 以前大三暑假实习的时候看到公司用SpringMVC而不是Struts2,老司机告诉我SpringMVC各种方便,各种解耦. 然后我自己试了试..好像是蛮方便的.... 基本上在Spring的基础 ...

  8. springMVC学习记录3-拦截器和文件上传

    拦截器和文件上传算是springmvc中比较高级一点的内容了吧,让我们一起看一下. 下面先说说拦截器.拦截器和过滤器有点像,都可以在请求被处理之前和请求被处理之到做一些额外的操作. 1. 实现Hand ...

  9. SpringMVC学习记录七——sjon数据交互和拦截器

    21       json数据交互 21.1      为什么要进行json数据交互 json数据格式在接口调用中.html页面中较常用,json格式比较简单,解析还比较方便. 比如:webservi ...

随机推荐

  1. Redis+MongoDB 最佳实践 做到读写分离 -摘自网络

    方案1. (被否定) 加上Redis,做到MongoDB的读写分离,单一进程从MongoDB及时把任务同步到Redis中. 看起来很完美,但是上线后出现了各种各样的问题,列举一下: 1.Redis队列 ...

  2. hdu4587-TWO NODES(割点)

    #include <bits/stdc++.h> using namespace std; ; ; struct Edge { int to, next; } edge[M]; int h ...

  3. JSON简介以及用法代码汇总

    什么是JSON? JavaScript 对象表示法(JavaScript Object Notation). JSON是一种轻量级的数据交换格式,某个JSON格式的文件内部譬如可以长成这样: { &q ...

  4. Android项目实战--手机卫士24--程序锁的实现以及逻辑

    昨天我们已经把程序全部读取出来,显示到界面上了,那今天,我们就来讲一下那个程序锁的实现啦.其实也很简单啦,我们主要就是把用户要锁定的程序放到一个表里面,然后就监听手机里面的任务栈,如果发现任务栈里面出 ...

  5. 使用openssl库实现des,3des加密

    原文地址: 使用openssl库实现des,3des加密 主要是调整了一下格式,以及一些变量的类型,以解决在VC2008下无法编译通过的问题. #include <stdio.h> #in ...

  6. 黑马程序猿_7K面试题之交通灯系统

    交通灯信号模拟系统 一.概述 模拟实现十字路口的交通灯管理系统逻辑,详细需求例如以下:(需求直接来源于老师的文档) ①      异步随机生成依照各个路线行驶的车辆. 比如: 由南向而来去往北向的车辆 ...

  7. 【问题汇总】ListView的FooterView设置可见性的问题

    ListView的FooterView一般用来给用户展示一些提示信息. 正常情况下,是这么使用的.代码例如以下: // footer footerLayout = new PullLoadingLay ...

  8. 未定义标识符_ConnectionPtr

    我的编译环境 vs2010 你会明白的图片,那么多 无用!

  9. Python 魔术方法指南

    入门 构造和初始化 构造定制类 用于比较的魔术方法 用于数值处理的魔术方法 表现你的类 控制属性访问 创建定制序列 反射 可以调用的对象 会话管理器 创建描述器对象 持久化对象 总结 附录 介绍 此教 ...

  10. interactive_timeout

    [mysqld] interactive_timeout  交互式连接 会话1 [root@localhost ~]# mysql -umysql -p Enter password: Welcome ...