SSM深入理解
来源:互联网 发布:机甲mesuit 知乎 编辑:程序博客网 时间:2024/06/06 03:36
配置文件spring:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<!-- 扫描除了controller之外的所有包 -->
<context:component-scan base-package="com.baway">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- 配置连接池 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/ems?characterEncoding=utf-8"></property>
<property name="username" value="root"></property>
<property name="password" value="123456"></property>
</bean>
<!-- 配置sqlsession -->
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="mapperLocations">
<list>
<value>classpath:com/baway/dao/*Mapper.xml</value>
</list>
</property>
<property name="typeAliasesPackage" value="com.baway.pojo"></property>
</bean>
<!-- 配置mapperScannerConigure -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.baway.dao"></property>
<property name="sqlSessionFactory" ref="sqlSession"></property>
</bean>
<!-- 配置事物管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 配置注解驱动 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
springmvc配值:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<!-- 包扫描 -->
<context:component-scan base-package="com.baway.controller"></context:component-scan>
<!-- 视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<mvc:annotation-driven/>
</beans>
映射文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.baway.dao.UserMapper">
<insert id="addUser" parameterType="user">
insert into user(name,password) value(#{name},#{password})
</insert>
<select id="selectByName" parameterType="string" resultType="user">
select * from user where name=#{name}
</select>
http://libs.baidu.com/jquery/1.10.2/jquery.min.js
</mapper>
webxml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<filter>
<filter-name>encoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
</web-app>
JackMaster_xh
- SSM深入理解
- SSM 之《深入理解mybatis原理》 MyBatis缓存机制的设计与实现
- SSM框架的理解
- ssm框架的理解
- ssm理解二
- 深入理解
- 浅谈对S2SH,SSM框架的理解
- ssm框架整合 理解及搭建
- SSM整合详解(个人理解)
- ssm+velocity项目理解(一)
- MapReduce理解-深入理解MapReduce
- 深入理解动态库
- 深入理解sizeof
- 深入理解MIDlet类
- 深入理解私有成员
- 深入理解动态库
- TCP协议深入理解
- TCP协议深入理解
- Standalone模式下Spark任务资源分配
- 关于DllRegisterServer的调用失败的问题解决办法 错误代码0x80040201
- windows media player不显示图像只有声音
- Android O 之行为变更
- maven scope含义的说明
- SSM深入理解
- Cookie
- CSMA/CD技术详解
- UIApplication详解 后台运行等
- 国嵌C语言 · 笔记 1:关键字
- c# 子窗体向父窗体传值
- 关于挖矿软件抽水的相关问题
- Druid0.10.0分布式部署配置
- maven 配置文件详解