SSM简单整合

SSM整合,SpringMVC,Spring,MyBatis的配置文件整合。

1.Spring和MyBatis的整合(applicationContext.xml)。

需要spring约束。

<?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:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd">
</beans>

整合Dao层配置:1.数据源配置 2.sqlSession工厂 3.dao层接口扫描

    <!-- dao层整合开始 --><!-- 数据源配置信息 --><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass" value="com.mysql.jdbc.Driver"/><property name="jdbcUrl" value="jdbc:mysql:///maven"/><property name="user" value="root"/><property name="password" value="root"/></bean><!--sqlsession工厂--><bean id="sqlSessionFacory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource"/><!--给pojo对象起别名,mapper映射中使用【注解开发可以省略】<property name="typeAliasesPackage" value="com.itheima.domain"/>--></bean><!--dao接口包下的接口进行扫描,使用sqlsession对象给其创建代理对象--><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="com.itheima.dao"/></bean><!-- dao层整合结束 -->

Service层整合配置:1.组件扫描  2.配置事务管理器  3.开启事务注解支持

    <!-- service层配置开始 --><!--组件扫描--><context:component-scan base-package="com.itheima.service"/><!--配置事务管理器--><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><!-- 事务的控制是利用connection对象控制的,所以需要传一个datasources对象 --><property name="dataSource" ref="dataSource"></property></bean><!--开启事务注解支持--><tx:annotation-driven /><!-- service层配置结束-->

2.Spring和SpringMvc的整合(springmvc.xml)。

springmvc.xml配置:1.组建扫描。 2.开启注解支持 3.视图解析器 4.释放静态资源。

<?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:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd"><!--组建扫描--><context:component-scan base-package="com.itheima.controller"/><!--开启注解支持--><mvc:annotation-driven/><!--试图解析器--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/pages/"/><property name="suffix" value=".jsp"/></bean><!--释放静态资源--><mvc:default-servlet-handler/></beans>

3.配置web.xml

web.xml配置需要:1.中文乱码过滤器  2.前端控制器  3.spring核心监听器

<web-app xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"version="3.0"><!-- 中文乱码过滤器--><filter><filter-name>encodingFilter</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>encodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><!--前端控制器--><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:springmvc.xml</param-value></init-param></servlet><servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>/</url-pattern></servlet-mapping><!--spring核心监听器--><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>

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/571008.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized 偶然遇到的mysql时区问题

因为换了个电脑用&#xff0c;运行时报了个很少见的异常。如下&#xff1a; Loading class com.mysql.jdbc.Driver. This is deprecated. The new driver class is com.mysql.cj.jdbc.Driver. The driver is automatically registered via the SPI and manual loading of the …

可持续字典树 Perfect Security

题目链接 题目大意:给你两个序列&#xff0c;第二个序列可以任意进行排列变换&#xff0c;然后由这两个序列一一异或得到答案序列&#xff0c;要求答案序列的字典序最小。 可持续字典树与第K大可持续线段树的区别主要在于每个节点上 &#xff0c;它多了一个记录值。 因为线段树…

Docker容器的简单操作及应用部署

1.什么是虚拟化 虚拟化&#xff08;Virtualization&#xff09;是一种资源管理技术 &#xff0c;虚拟化技术种类很多&#xff0c;例如&#xff1a;软件虚拟化、硬件虚拟化、内存虚拟化、网络虚拟化(vip)、桌面虚拟化、服务虚拟化、虚拟机等等 。 2.什么是Docker Docker 是一个…

PHP 数据库连接池实现(转)

转自https://blog.csdn.net/Marksinoberg/article/details/53857511 摘要xml 读取配置文件 简易方式常规方式PHP解析XML 配置文件解析数据库连接池测试 申请过多时拒绝请求已满后拒绝放入总结此文着实无聊&#xff0c;不要浪费时间往下看啦 摘要 之前总是以脚本面向过程的方式…

Jenkins的安装和卸载(转载)

今天安装jenkins后因为网路问题一开始没自动安装插件&#xff0c;后来想重新卸载安装一遍jenkins。找了一会才找到一篇,jenkins的卸载&#xff08;linux下&#xff0c;已尝试可以&#xff09; https://blog.csdn.net/chunlongyuan/article/details/79243143 最后jenkins服务仍…

codeforces 453C Little Pony and Summer Sun Celebration

codeforces 453C Little Pony and Summer Sun Celebration 这道题很有意思&#xff0c;虽然网上题解很多了&#xff0c;但是我还是想存档一下我的理解。 题意可以这样转换&#xff1a;初始所有点有 \(01\) 状态&#xff0c;每经过一次状态就翻转&#xff0c;求一条路径使得最后…

MongoDB无法注册windows服务问题解决 Error connecting to the Service Control Manager: 拒绝访问 Mongodb M

发现在mongodb.log里出现 2017-07-07T17:01:55.3390800 I CONTROL [main] Error connecting to the Service Control Manager: 拒绝访问。 (5) 错误 1.检查mongodb.conf配置内容是否有误. 2.cmd需要以管理员方式启动(c盘system32下cmd.exe). 3.执行mongod.exe --bind_ip 1…

保存图片验证码到redis数据库

def get_image_code(image_code_id): # 1 实用工具类生成验证码 name, text, image_data captcha.generate_captcha() #将验证码的数据和编号存储到 redis 中 try: #redis_store.set() 设置数据 #redis_store.expires()设置有效期 #setex&#xff1a;设置数据的同时设置有效期…

Eclipse项目无错误但是有红叉问题解决

这个问题可以从两方面下手。 1.是项目右键 ->properties ->java buildpath 解决里面的红叉问题。 2.就是项目.classpth文件问题解决 首先window ->show view-> other ->找到problem 如果是 The project cannot be built until build path errors are resol…

批量处理JDBC语句提高处理速度

当需要成批插入或者更新记录时。可以采用Java的批量更新机制&#xff0c;这一机制允许多条语句一次性提交给数据库批量处理。通常情况下比单独提交处理更有效率JDBC的批量处理语句包括下面两个方法&#xff1a;– addBatch(String)&#xff1a;添加需要批量处理的SQL语句或…

TCP close_wait内幕

最近调试时遇到一个tcp连接 一发交易server端就从es连接状态变成close_wait状态的问题。 tcp连接需要三次握手&#xff0c;而被动关闭连接则是需要四次握手的&#xff0c;不能说单方面关闭连接就是成功关闭连接了。 首先我们要搞清楚close_wait出现的机制和原理。 close_wai…

p-value

p-value p-value翻译为假定值&#xff0c;假设几率。我们在生物信息中通常使用p值方法&#xff08;P-Value, Probability, Pr&#xff09;来做检验。那么p-value是什么呢&#xff1f;其实P-value就是一种概率&#xff0c;表示在原假设为真的前提下出现观察样本以及更极端情况的…

webstorm激活

2018-12-20(最新可用&#xff0c;选中间的activetion code)&#xff1a; 前提&#xff1a;修改本地的hosts配置文件&#xff08;/etc/hosts&#xff09; 最后一行新增这句话&#xff1a;0.0.0.0 account.jetbrains.com 然后去 http://idea.lanyus.com/ 这个网站生成一个激活码…

面向对象初调用:foolish 电梯

本周我们完成的任务是傻瓜电梯的调度&#xff0c;对于那十分十分详细的指导书&#xff0c;我感觉想要说明白题目要求&#xff0c;是做不到的&#xff0c;所以就把指导书贴出来给大家看了&#xff0c;&#xff0c;由于在下还不会网页制作&#xff0c;只能通过百度网盘了&#xf…

Studio 3T更改使用时间破解免费使用方式(转,可以使用)

echo off ECHO 重置Studio 3T的使用日期...... FOR /f "tokens1,2,* " %%i IN (reg query "HKEY_CURRENT_USER\Software\JavaSoft\Prefs\3t\mongochef\enterprise" ^| find /V "installation" ^| find /V "HKEY") DO ECHO yes | reg a…

Maven学习之(一)基本配置

安装maven还几次没成功&#xff0c;不过最后还是查资料成功了&#xff0c;所以记录一下。 1.安装JDK&#xff0c;比较简单&#xff0c;就不说明了。 2.配置java的环境变量 JAVA_HOME &#xff08;最开始因为java配置成C:\Program Files (x86)\Java\jdk1.8.0_144\bin 所以出问题…

Rabbitmq java.util.concurrent.TimeoutException小问题解决

最近在研究rabbitmq的各个工作模式时。 出现了一个rabbitmq java.util.concurrent.TimeoutException异常 java.util.concurrent.TimeoutExceptionat com.rabbitmq.utility.BlockingCell.get(BlockingCell.java:77)at com.rabbitmq.utility.BlockingCell.uninterruptibleGet(B…

个人服务器

1、用yum install 安装太方便了&#xff0c;不用考虑依赖 yum install java yum install mysql yum install tomcat 一下子就搞定了。 安装好mysql好像并不能启动&#xff0c;还要yum install mariadb-server -y 具体看&#xff1a;https://blog.csdn.net/lixingdefeng…

org.hibernate.QueryTimeoutException: Could not execute JDBC batch update问题解决(转)

这个bug的原因就是 在插入数据操作时 插入字段的长度 超出了数据库表设计时的该字段长度 导致的这个异常 解决办法&#xff1a; 1.减短字段长度 2.增加字段长度限制 例&#xff1a;alter table table_name modify column_name varchar(50); 转&#xff1a;https://blo…

Neither BindingResult nor plain target object for bean name 'xxx' availabl问题解决

明明已经按网上进行处理了为什么还是这个异常呢&#xff1f; 解决方法&#xff1a; 1.<form:form modelAttribute"user" 标签内绑定页面传来的数据。 2.在页面上加上 <jsp:useBean id"command" class"com.mvc.domain.BlogForm" scope&q…