springmvc
1.导入价包
2.web.xml设置dispatherServlet
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
</servlet>
3.applicationContext.xml设置
<mvc:annotation-driven></mvc:annotation-driven>
4.注解controller层
@RequestMapping()注解方法
重定向与转发
默认转发
return "redirect:show.jsp";
return "redirect:show";
return "show.jsp";
模型驱动和获取属性
通过参数获得
("aa")
public String aa(User user,String modify){
}
整合mvcspring和mybatis
1.导入价包(mybatis-spring-1.1.1.jar)
2.创建sessionFactory
dataSource
<bean
class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="locations">
<value>classpath:db.properties</value>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="url" value="${url}"></property>
<property name="username" value="${username}"></property>
<property name="password" value="${password}"></property>
<property name="driverClassName" value="${driver}"></property>
</bean>
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property> <!-- 设置dataSource -->
<property name="mapperLocations" value="classpath:com/mapper/*.xml"></property><!-- 设置mapepr映射路径 -->
</bean>
<bean id="mcf" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.dao"></property>
<property name="sqlSessionFactoryBeanName" value="sessionFactory"></property>
</bean><!-- 设置MapperScannerConfigurer -->
最后实现dao层的注入@Autowired