参考:https://blog.csdn.net/qq_41541619/article/details/82459873
SpringMVC 常用注解都有哪些?
-
@Controller,使用它标记的类就是一个SpringMVC Controller 对象
-
@RequestMapping,处理请求映射地址
-
@PathVariable,用于对应restful风格url中的参数
@RequestMapping(value="/happy/{dayid}")
findPet(@PathVariable String dayid) -
@RequestParam,将请求的参数绑定到方法中的参数上
@RequestParam(value = “name”, required = false) String name -
@ResponseBody,将返回类型直接输入到http response body中
-
@RequestBody,方法参数直接被绑定到http request body中
-
@ModelAttribute和@SessionAttributes,用来传递和保存数据,有很多的坑,不建议使用
-
控制反转
@Component,标注为一个普通的bean
@Service(实现接口中需要注解)
@Repository(常用于获取数据库查询接口dao接口类) -
依赖注入
@Autowired
@Qulifier
@Resource
@Value -
全局
@Configuration,代替配置文件,相当于beans
@ComponentScan,配置扫描包
@Scope,配置bean的生命周期
二.<context:annotation-config/>
<mvc:annotation-driven />
三.
1.配置post请求乱码问题在web.xml中
2.配置请求地址格式web.xml中
四.Spring bean 的生命周期(11步)
前提是实体类实现了相应的接口
spring上下文中的bean的生命周期:
1.实例化bean对象
2.注入bean的所有属性
3.设置bean的id
调用BeanNameAware接口的setBeanName(String)方法
4.设置bean工厂
调用BeanFactoryAware接口的setBeanFactory()方法
5.设置实例所在的上下文空间
调用ApplicationContextAware接口的setApplicationContext()方法,传入Spring上下文
6.调用后置处理器的预初始化方法
调用BeanPostProcessor接口的postProcessorBeforeInitialization()方法
7.执行InitializingBean的afterPropertiesSet()
8.调用使用init-method配置的自定义初始化方法
9.调用后置处理器的后初始化方法
调用BeanPostProcessor接口的postProcessorAfterInitialization()方法
10.调用DisPosableBean接口的destory()方法
11.调用使用destroy-method配置的自定义销毁由方法
<!-- c3p0数据库连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">