1、新建maven项目,在pom.<project ="http://maven.apache.org/POM/4.0.0" ="http://www.w3.org/2001/ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 >> <modelVersion>4.0.0</modelVersion> <groupId>demoGroup</groupId> <artifactId>websocket</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <!-- 设置 Spring 的版本 --> <spring.version>4.1.2.RELEASE</spring.version> <!-- mybatis版本号 --> <mybatis.version>3.2.8</mybatis.version> <postgresql.driver.version>9.3-1101-jdbc4</postgresql.driver.version> <org.springframework.version>4.1.2.RELEASE</org.springframework.version> <org.slf4j.version>1.6.6</org.slf4j.version> </properties> <dependencies> <!-- junit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12-beta-3</version> <scope>test</scope> </dependency> <!-- log4j --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <!-- spring 的基本依赖 开始 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> </dependency> <!-- spring 的基本依赖 结束 --> <!-- mybatis核心包 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <!-- mybatis/spring包 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.2.2</version> </dependency> <!-- postgresql驱动 依赖 --> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>${postgresql.driver.version}</version> </dependency> <!-- c3p0连接池 --> <dependency> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> <version>0.9.1.2</version> </dependency> <!-- Spring WebSocket --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-websocket</artifactId> <version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>1.9.4</version> </dependency> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-core-asl</artifactId> <version>1.9.4</version> </dependency> </dependencies> </project>
2、在java目录下创建entity、dao、server、controller等主要目录
3、在resource中创建mapper文件夹,用于存放mybatis的mapper.
4、在resource中创建jdbc.properties文件,用于配置数据库连接参数
# jdbc要和依赖中的对应jdbc.driver=org.postgresql.Driverjdbc.url=jdbc:postgresql://127.0.0.1:5432/dm_video_demojdbc.username=postgresqljdbc.password=123456
5、在resource中创建mybatis.<??><!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration> <!-- 配置全局属性 --> <settings> <!-- 使用jdbc的getGeneratedKeys获取数据库自增主键值 --> <setting name="useGeneratedKeys" value="true" /> <!-- 使用列别名替换列名 默认:true --> <setting name="useColumnLabel" value="true" /> <!-- 开启驼峰命名转换:Table{a_bc} -> Entity{aBc} --> <setting name="mapUnderscoreToCamelCase" value="true" /> </settings></configuration>
6、在resource中创建spring_dao.<??><beans ="http://www.springframework.org/schema/beans" ="http://www.w3.org/2001/ ="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans >> <!-- 配置整合mybatis过程 --> <!-- 1.配置数据库相关参数properties的属性:${url} --> <context:property-placeholder location="classpath:jdbc.properties" /> <!-- 2.数据库连接池 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <!-- 配置连接池属性 --> <property name="driverClass" value="${jdbc.driver}" /> <property name="jdbcUrl" value="${jdbc.url}" /> <property name="user" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <!-- c3p0连接池的私有属性 --> <property name="maxPoolSize" value="30" /> <property name="minPoolSize" value="10" /> <!-- 关闭连接后不自动commit --> <property name="autoCommitOnClose" value="false" /> <!-- 获取连接超时时间 --> <property name="checkoutTimeout" value="10000" /> <!-- 当获取连接失败重试次数 --> <property name="acquireRetryAttempts" value="2" /> </bean> <!-- 3.配置SqlSessionFactory对象 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 注入数据库连接池 --> <property name="dataSource" ref="dataSource" /> <!-- MyBaties配置文件:mybatis.--> <property name="configLocation" value="classpath:mybatis. /> <!-- 扫描entity包 使用别名 --> <property name="typeAliasesPackage" value="com.test.entity" /> <!-- 扫描sql配置文件:mapper需要的--> <property name="mapperLocations" value="classpath:mapper/*. /> </bean> <!-- 4.配置扫描Dao接口包,动态实现Dao接口,注入到spring容器中 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!-- 注入sqlSessionFactory --> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> <!-- 给出需要扫描Dao接口包 --> <property name="basePackage" value="com.test.dao" /> </bean></beans>
7、在resource中创建spring_server.<??><beans ="http://www.springframework.org/schema/beans" ="http://www.w3.org/2001/ ="http://www.springframework.org/schema/context" ="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans >> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!-- 注入数据库连接池 --> <property name="dataSource" ref="dataSource" /> </bean> <!-- 配置基于注解的声明式事务 --> <tx:annotation-driven transaction-manager="transactionManager" /></beans>
8、在resource中创建spring_mvc.<??><beans ="http://www.springframework.org/schema/beans" ="http://www.w3.org/2001/ ="http://www.springframework.org/schema/context" ="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans >> <!-- 注解扫描文件 --> <context:component-scan base-package="com.test.controller"/> <context:component-scan base-package="com.test.dao"/> <context:component-scan base-package="com.test.server"/> <context:component-scan base-package="com.test.socket"/> <!-- 静态资源放行 --> <mvc:resources location="/static/" mapping="/static/**"/> <!-- 配置SpringMVC --> <!-- 1.开启SpringMVC注解模式 --> <mvc:annotation-driven /> <!-- 2.静态资源默认servlet配置 (1)加入对静态资源的处理:js,gif,png (2)允许使用"/"做整体映射 --> <mvc:default-servlet-handler/> <!-- 3.配置jsp 显示ViewResolver --> <!-- jsp响应路径 --> <bean id="viewResolverJsp" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> <property name="order" value="1"/> </bean></beans>
9、修改web.<??><web-app ="http://www.w3.org/2001/ ="http://java.sun.com/ xsi:schemaLocation="http://java.sun.com/ version="2.5"> <display-name>websocket</display-name> <!-- <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list>--> <!-- 区分项目名称,防止重名 --> <context-param> <param-name>websocket</param-name> <param-value>maven.example.root</param-value> </context-param> <!-- Spring的log4j监听器 --> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <!-- 字符集 过滤器 --> <filter> <filter-name>CharacterEncodingFilter</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> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- Spring view分发器 --> <servlet> <servlet-name>springMvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 配置需要加载的配置文件 spring-dao.--> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-*.</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- 默认匹配所有的请求 --> <servlet-mapping> <servlet-name>springMvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping></web-app>
<??><beans ="http://www.springframework.org/schema/beans" ="http://www.w3.org/2001/ ="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans >> <!-- 配置整合mybatis过程 --> <!-- 1.配置数据库相关参数properties的属性:${url} --> <context:property-placeholder location="classpath:jdbc.properties" /> <!-- 2.数据库连接池 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <!-- 配置连接池属性 --> <property name="driverClass" value="${jdbc.driver}" /> <property name="jdbcUrl" value="${jdbc.url}" /> <property name="user" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <!-- c3p0连接池的私有属性 --> <property name="maxPoolSize" value="30" /> <property name="minPoolSize" value="10" /> <!-- 关闭连接后不自动commit --> <property name="autoCommitOnClose" value="false" /> <!-- 获取连接超时时间 --> <property name="checkoutTimeout" value="10000" /> <!-- 当获取连接失败重试次数 --> <property name="acquireRetryAttempts" value="2" /> </bean> <!-- 3.配置SqlSessionFactory对象 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 注入数据库连接池 --> <property name="dataSource" ref="dataSource" /> <!-- MyBaties配置文件:mybatis.--> <property name="configLocation" value="classpath:mybatis. /> <!-- 扫描entity包 使用别名 --> <property name="typeAliasesPackage" value="com.test.entity" /> <!-- 扫描sql配置文件:mapper需要的--> <property name="mapperLocations" value="classpath:mapper/*. /> </bean> <!-- 4.配置扫描Dao接口包,动态实现Dao接口,注入到spring容器中 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!-- 注入sqlSessionFactory --> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> <!-- 给出需要扫描Dao接口包 --> <property name="basePackage" value="com.test.dao" /> </bean></beans>
7、在resource中创建spring_server.<??><beans ="http://www.springframework.org/schema/beans" ="http://www.w3.org/2001/ ="http://www.springframework.org/schema/context" ="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans >> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!-- 注入数据库连接池 --> <property name="dataSource" ref="dataSource" /> </bean> <!-- 配置基于注解的声明式事务 --> <tx:annotation-driven transaction-manager="transactionManager" /></beans>
8、在resource中创建spring_mvc.<??><beans ="http://www.springframework.org/schema/beans" ="http://www.w3.org/2001/ ="http://www.springframework.org/schema/context" ="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans >> <!-- 注解扫描文件 --> <context:component-scan base-package="com.test.controller"/> <context:component-scan base-package="com.test.dao"/> <context:component-scan base-package="com.test.server"/> <context:component-scan base-package="com.test.socket"/> <!-- 静态资源放行 --> <mvc:resources location="/static/" mapping="/static/**"/> <!-- 配置SpringMVC --> <!-- 1.开启SpringMVC注解模式 --> <mvc:annotation-driven /> <!-- 2.静态资源默认servlet配置 (1)加入对静态资源的处理:js,gif,png (2)允许使用"/"做整体映射 --> <mvc:default-servlet-handler/> <!-- 3.配置jsp 显示ViewResolver --> <!-- jsp响应路径 --> <bean id="viewResolverJsp" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> <property name="order" value="1"/> </bean></beans>
9、修改web.<??><web-app ="http://www.w3.org/2001/ ="http://java.sun.com/ xsi:schemaLocation="http://java.sun.com/ version="2.5"> <display-name>websocket</display-name> <!-- <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list>--> <!-- 区分项目名称,防止重名 --> <context-param> <param-name>websocket</param-name> <param-value>maven.example.root</param-value> </context-param> <!-- Spring的log4j监听器 --> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <!-- 字符集 过滤器 --> <filter> <filter-name>CharacterEncodingFilter</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> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- Spring view分发器 --> <servlet> <servlet-name>springMvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 配置需要加载的配置文件 spring-dao.--> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-*.</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- 默认匹配所有的请求 --> <servlet-mapping> <servlet-name>springMvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping></web-app>
<??><beans ="http://www.springframework.org/schema/beans" ="http://www.w3.org/2001/ ="http://www.springframework.org/schema/context" ="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans >> <!-- 注解扫描文件 --> <context:component-scan base-package="com.test.controller"/> <context:component-scan base-package="com.test.dao"/> <context:component-scan base-package="com.test.server"/> <context:component-scan base-package="com.test.socket"/> <!-- 静态资源放行 --> <mvc:resources location="/static/" mapping="/static/**"/> <!-- 配置SpringMVC --> <!-- 1.开启SpringMVC注解模式 --> <mvc:annotation-driven /> <!-- 2.静态资源默认servlet配置 (1)加入对静态资源的处理:js,gif,png (2)允许使用"/"做整体映射 --> <mvc:default-servlet-handler/> <!-- 3.配置jsp 显示ViewResolver --> <!-- jsp响应路径 --> <bean id="viewResolverJsp" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> <property name="order" value="1"/> </bean></beans>
9、修改web.<??><web-app ="http://www.w3.org/2001/ ="http://java.sun.com/ xsi:schemaLocation="http://java.sun.com/ version="2.5"> <display-name>websocket</display-name> <!-- <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list>--> <!-- 区分项目名称,防止重名 --> <context-param> <param-name>websocket</param-name> <param-value>maven.example.root</param-value> </context-param> <!-- Spring的log4j监听器 --> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <!-- 字符集 过滤器 --> <filter> <filter-name>CharacterEncodingFilter</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> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- Spring view分发器 --> <servlet> <servlet-name>springMvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 配置需要加载的配置文件 spring-dao.--> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-*.</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- 默认匹配所有的请求 --> <servlet-mapping> <servlet-name>springMvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping></web-app>
原文转载:http://www.shaoqun.com/a/512457.html
贸发局:https://www.ikjzd.com/w/1621
亿恩网:https://www.ikjzd.com/w/1461
1、新建maven项目,在pom.<project="http://maven.apache.org/POM/4.0.0"="http://www.w3.org/2001/xsi:schemaLocation="http://maven.apache.org/POM/4.0.0>><modelVersion>4.0.0</
55海淘:55海淘
环球易购:环球易购
去马尔代夫如何预防安全问题?:去马尔代夫如何预防安全问题?
"混血男神"Ben:卖家关心的亚马逊FBA索赔问题,我有话要说:"混血男神"Ben:卖家关心的亚马逊FBA索赔问题,我有话要说
亚马逊要求提供儿童学校用品的安全证明 / 美国总统关税权力有望得到限制:亚马逊要求提供儿童学校用品的安全证明 / 美国总统关税权力有望得到限制
没有评论:
发表评论