一、ssm开发重点
(1)web.xml配置全局初始化参数是为了帮我们创建IOC容器?
(2)/拦截的都以为是控制器,以为都要通过前端控制器的,所以我们的静态资源就获取不到了,要开启静态资源访问:
springmvc里面的前端控制器的拦截/是拦截所以的控制器请求,若是控制器(浏览器输入的controller的某个映射)都要被前端控制器拦截,如果我们在浏览器访问的是静态资源如.jpg或者.git。这时我们就要开启静态资源访问权限,让默认servlet来专门处理这些静态资源jpg。
(3)spring-mvc.xml配置过滤器是防止post请求乱码的
1.直接回显数据要用的(注解驱动,必须加,不然回写对象和集合会很麻烦
):
2.form不要name(你写也可以),表单项才要name(input为summit可不要name):
3.ajax返回类型:
6.一般是在Controller调用service的方法,而service是调用dao的方法。
7.在sqlMapConfig.xml加载xxxMapper.xml文件,UserMapper.xml写的是对应mapper层(dao)接口的sql语句。mybatis就是省略了(mapper)dao的impl而已,但是mapper的接口还是得写的。然后spring可以简化创建多态的实现类,一般在service使用。而Springmvc是负责Controller层,jsp请求给Controller,然后Controller调用Service层,Service调用mapper层。
8.一般spring-mvc只负责controller的包,而applicationContext.xml是负责业务的包如dao、service等包,就是分几个xml把业务和逻辑控制分开来。
9.在Controller类中注入service(不是写ServiceImpl哦)。在ServiceImpl类中注入mapper接口。mapper接口与xxxMapper.xml组合起来了,它不用注入其mapper的实现类的(其中applicationContext.xml会扫描mapper层自动创建其实现类的),因为mapper层没有impl,xxxMapper.Xml会在sqlMapConfig.xml加载被加载的,相当于impl了。(接口要和放接口的xml的包名要一样才被扫描到,否则报错,困扰我好几天了)
10.在resources建包得用/分隔,在java建包就可以用点分隔
二、各自配置文件用途
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!--组件扫描 扫描service和mapper-->
<context:component-scan base-package="com.itheima">
<!--排除controller的扫描-->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"></context:exclude-filter>
</context:component-scan>
<!--加载propeties文件-->
<context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
<!--配置数据源信息-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"></property>
<property name="jdbcUrl" value="${jdbc.url}"></property>
<property name="user" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<!--配置sessionFactory-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!--加载mybatis核心文件-->
<property name="configLocation" value="classpath:sqlMapConfig.xml"></property>
</bean>
<!--扫描mapper.xml(也要和接口的包名一致才行,也可以说是扫接口)所在的包 为mapper创建实现类-->
<bean