• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Java > 详解spring+springmvc+mybatis整合注解

详解spring+springmvc+mybatis整合注解

作者:White_Black007 字体:[增加 减小] 来源:互联网 时间:2017-05-28

White_Black007 通过本文主要向大家介绍了springmvc注解详解,springmvc详解,springmvc配置详解,springmvc框架详解,springmvc原理详解等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

每天记录一点点,慢慢的成长,今天我们学习了ssm,这是我自己总结的笔记,大神勿喷!谢谢,主要代码!! !

spring&springmvc&mybatis整合(注解)

1.jar包

2.引入web.xml文件

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <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>*.action</url-pattern>
</servlet-mapping>

</div>

3.创建实体类

4.引入一个(类名)dao.xml

<update id="update" parameterType="accounting" >
    update accounting set money=#{money} where name=#{name}
  </update>
  <select id="findMoneyByName" parameterType="string" resultType="accounting">
    select * from accounting where name=#{name}
</select>
</div>

5.创建一个(类名)dao

public void update(Accounting a);
public Accounting findMoneyByName(String name);
</div>

6.写service

public void remit(String from,String to,double money);
</div>

7.写serviceimpl

@Service
public class AccountServiceImpl implements AccountService {
  @Autowired
  private AccountDao ad;
  @Override
  public void remit(String from, String to, double money) {
    Accounting fromAccount=ad.findMoneyByName(from);
    fromAccount.setMoney(fromAccount.getMoney()-money);
    ad.update(fromAccount);
    Accounting toAccount=ad.findMoneyByName(to);
    toAccount.setMoney(toAccount.getMoney()+money);
    ad.update(toAccount);
  }

}

</div>

8.引入applicationContext.xml

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-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/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">

  <!-- 加载db.properties文件中的内容,db.properties文件中key命名要有一定的特殊规则 -->
  <context:property-placeholder location="classpath:db.properties" />
  <!-- 配置数据源 ,dbcp -->

  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="${jdbc.driver}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
    <property name="maxActive" value="30" />
    <property name="maxIdle" value="5" />
  </bean>
  <!-- sqlSessionFactory -->
  <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <!-- 数据库连接池 -->
    <property name="dataSource" ref="dataSource" />
    <!-- 加载mybatis的全局配置文件 -->
    <property name="configLocation" value="classpath:sqlMapConfig.xml" />
  </bean>


  <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
  </bean>
  <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
      <tx:method name="*" propagation="REQUIRED"/>
    </tx:attributes>
  </tx:advice>
  <aop:config>
    <aop:advisor advice-ref="txAdvice" pointcut="execution(* service..*.*(..))"/>
  </aop:config>


  <!-- mapper扫描器 -->
  <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <!-- 扫描包路径,如果需要扫描多个包,中间使用半角逗号隔开 -->
    <property name="basePackage" value="dao"></property>
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
  </bean>

</beans>

</div>

9.引入db.properties文件和log4j.properties文件

10.引入springmvc.xml文件

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-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/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">
  <mvc:annotation-driven></mvc:annotation-driven>
  <context:component-scan base-package="action"></context:component-scan>
  <context:component-scan base-package="service"></context:component-scan>
</beans>

</div>

11.jsp页面编写

//index.jsp:
 <form action="account_execute.action" method="post">
  汇款人:<input type="text" name="from"/>
  收款人:<input type="text" name="to"/>
  钱数:<input type="text" name="money"/>
  <input type="submit"/>
 </form>
//message.jsp
${message }
</div>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

</div>
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • springMvc注解之@ResponseBody和@RequestBody详解
  • Spring依赖注入的两种方式(根据实例详解)
  • 详解如何用spring Restdocs创建API文档
  • 详解Spring简单容器中的Bean基本加载过程
  • 详解springmvc之json数据交互controller方法返回值为简单类型
  • 详解springMVC之与json数据交互方法
  • 详解SpringMVC和MyBatis框架开发环境搭建和简单实用
  • 详解Spring-Boot集成Spring session并存入redis
  • spring的几个重要类和接口(详解)
  • 详解spring+springmvc+mybatis整合注解

相关文章

  • 2017-05-28实例解析JAVA中代码的加载顺序
  • 2017-05-28java版简单的猜数字游戏实例代码
  • 2017-05-28Java 队列 Queue 用法实例详解
  • 2017-05-28Java生产者和消费者例子_动力节点Java学院整理
  • 2017-05-28Java equals 方法与hashcode 方法的深入解析
  • 2017-05-28java 中平方根(sqrt)算法 的实例详解
  • 2017-05-28Java构造方法实例详解(动力节点java学院整理)
  • 2017-05-28详解Java反射实现Aop代理
  • 2017-05-28java 对文件夹目录进行深度遍历实例代码
  • 2017-05-28Java追加文件内容的三种方法实例代码

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 详解spring整合shiro权限管理与数据库设计
    • 浅析java修饰符访问权限(动力节点Java学院整理)
    • 详解SpringBoot配置devtools实现热部署
    • SpringBoot下的值注入(推荐)
    • 详解spring封装hbase的代码实现
    • 详解Java动态加载数据库驱动
    • Eclipse 开发java 出现Failed to create the Java Virtual Machine错误解决办法
    • Java微信公众平台开发(1) 接入微信公众平台
    • Java SpringMVC实现国际化整合案例分析(i18n)
    • 面向对象编程:Java中的抽象数据类型

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有