事务管理:

使用AspectJ的AOP配置管理事务

<?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"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.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/contexthttp://www.springframework.org/schema/context/spring-context.xsd"><!-- 加载jdbc属性文件 --><context:property-placeholder location="jdbc.properties"/><!-- 注册c3p0数据源 --><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass" value="${jdbc.driver}"></property><property name="jdbcUrl" value="${jdbc.url}"></property><property name="user" value="${jdbc.username}"></property><property name="password" value="${jdbc.password}"></property></bean><!-- 注册银行账户dao --><bean id="accountDaoImpl" class="com.zc.dao.impl.AccountDaoImpl"><property name="dataSource" ref="dataSource"></property></bean><!-- 注册基金账户dao --><bean id="fundDaoImpl" class="com.zc.dao.impl.FundDaoImpl"><property name="dataSource" ref="dataSource"></property></bean><!-- 注册service --><bean id="fundServiceImpl" class="com.zc.service.impl.FundServiceImpl"><property name="accountDaoImpl" ref="accountDaoImpl"></property><property name="fundDaoImpl" ref="fundDaoImpl"></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>

使用注解配置事务:

加入@Transactional(rollbackFor=FundException.class),同时在配置文件中配置事务注解驱动

   <!-- 配置事务注解驱动 --><tx:annotation-driven transaction-manager="transactionManager"/>

SpringMVC:

MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,它是一种软件设计典范,是一种软件架构设计分层模式。

Model(模型)是应用程序中用于处理应用程序数据逻辑的部分

View(视图)是应用程序中处理数据显示的部分。

Controller(控制器)是应用程序中处理用户交互的部分。

最典型的MVC就是JSP + servlet + javabean的模式。

MVC发展历史

Model 1 (jsp+javabean)

Model 2 (jsp+servlet+javabean)

Model1和Model2的优缺点

Model1:好处:简单、快速开发、适用小规模开发;缺点:业务逻辑和表示逻辑混合在JSP页面中没有进行抽象和分离,JSP负载太大,所以非常不利于应用系统业务的重用和改动,不便于维护

Model2:好处:具有组件化的优点从而更易于实现对大规模系统的开发和管理,职责划分清晰

目前市场上MVC框架

1 SpringMVC(主流MVC框架):是spring框架的一部分(子框架),是实现对Servlet技术进行封装。

2.Struts

3.Jfinal

SpringMVC运行原理

开发步骤:

1导入jar包

2配置web.xml,注册SpringMVC前端控制器(中央调度器)

<?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_2_5.xsd" id="WebApp_ID" version="2.5"><display-name>springmvc</display-name><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list><!--  <servlet-mapping><servlet-name>default</servlet-name><url-pattern>*.png</url-pattern></servlet-mapping> --><!-- 注册springmvc前端控制器(中央调度器) --><servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!-- 指定springmvc配置文件的路径以及名称 --><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>
</web-app> 

3编写SpringMVC后端控制器

package com.zc.handlers;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
/*** 后端控制器* @author 14687**/
public class MyController implements Controller{@Overridepublic ModelAndView handleRequest(HttpServletRequest request,HttpServletResponse response) throws Exception {ModelAndView mv = new ModelAndView();mv.addObject("msg", "springMVC");mv.setViewName("/welcome.jsp");//跳转的视图的路径return mv;}}

4编写springmvc配置文件,注册后端控制器(注意id写法格式)

<?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:mvc="http://www.springframework.org/schema/mvc"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"><!-- 注册后端控制器 --><bean id="/my.do" class="com.zc.handlers.MyController"></bean><mvc:default-servlet-handler/>
</beans>

5编写跳转资源页面

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"><title>My JSP 'welcome.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body>${msg}</body>
</html>

web.xml中urlpattern配置问题

配置/和配置/*的区别

/拦截静态资源、/*拦截路径和页面,如果配置成/*会把页面拦截掉显示不出来

spring mvc后端代码实现弹出对话框_Spring(3)——事务管理和MVC相关推荐

  1. spring mvc后端代码实现弹出对话框_伟源|一图搞定Spring框架

    很多朋友都问济宏同学,现在流行的Java到底是什么鬼?如何快速入门,快速上手? 济宏同学也在网上找了很多文章,但是没有一个文章能说得清楚.所以,济宏同学只好通过脑图方式,给小白们给一个Java现在最流 ...

  2. MVC中执行成功弹出对话框

    Control中:ViewDate["Msg"]="添加成功"; View中:<td id="tdMsg" style="d ...

  3. html弹窗确认取消公告代码,js 弹出确认与取消对话框的四种方法

    1,js弹出删除确认框 复制代码 代码示例: 弹出窗口 2,js删除前确认 复制代码 代码示例: function delete_confirm(e) { if (event.srcelement.o ...

  4. php 弹窗代码大全,PHP_asp.net弹出窗口代码大全,//关闭,父窗口弹出对话框,子窗 - phpStudy...

    asp.net弹出窗口代码大全 //关闭,父窗口弹出对话框,子窗口直接关闭 this.Response.Write(""); //关闭,父窗口和子窗口都不弹出对话框,直接关闭 th ...

  5. php网页,想弹出对话框, 消息框 简单代码

    php网页,想弹出对话框, 消息框 简单代码 <?php echo "<script language=\"JavaScript\">alert(\&q ...

  6. HTML点击按钮弹出对话框(仅代码)

    HTML点击按钮弹出对话框的代码(整个网页): <!doctype html> <html> <head><title>无标题文档</title& ...

  7. html自动弹出提示对话框代码,html5简单的手机端弹出对话框确认代码

    特效描述:html5手机端 弹出对话框确认.html5手机端弹出对话框 代码结构 1. 引入JS 2. HTML代码 没有传递任何参数(需手动关闭) 弹出一个不带任何按钮,且是警告的框,并且两秒后自动 ...

  8. android+底部评论框,Android 之BottomsheetDialogFragment仿抖音评论底部弹出对话框效果(实例代码)...

    实现的效果图: 自定义Fragment继承BottomSheetDialogFragment 重写它的三个方法: onCreateDialog() onCreateView() onStart() 他 ...

  9. 网页弹出对话框的几种代码

    [1.最基本的弹出窗口代码]其实代码非常简单: <script LANGUAGE="javascript"> <!-- window.open ("pa ...

最新文章

  1. 1008 Elevator
  2. 微信小程序开发分销制度济南_花店微信小程序开发教程
  3. php过滤两个坐标,php判断两个坐标的方位角
  4. oracle 日期 extract,ORACLE——EXTRACT() 截取日期时间的函数使用
  5. qt ui框架_5个开源Python GUI框架
  6. 安卓 java编译_Android源码分析(七)-----如何解决java编译版本问题
  7. scala学习---2
  8. 项目经理常见的沟通坏习惯
  9. 11下滑半个屏幕_努比亚发布手表手机:柔性屏幕,体积感人
  10. .NET 重生之旅——序言
  11. python3创建类_python3 metaclass--创建类的过程分析
  12. python判断linux中文件是否存在_linux shell 中判断文件、目录是否存在的方法
  13. python3 mysql插入数据冲突
  14. specification jpa 复杂查询
  15. 6个好用免费的LiDAR数据处理软件【2021最新】
  16. AES加解密原理详解与算法实现
  17. win10中Charles从下载安装到证书设置和雷电模拟器或浏览器中抓包测试
  18. 招聘:JAVA软件开发工程师
  19. 《AngularJS深度剖析与最佳实践》简介
  20. php 自定义图片排版,照片拼图在线制作 自带多种照片拼图模板,自由排版将多张照片合成一张...

热门文章

  1. 不敢相信?System.currentTimeMillis()存在性能问题
  2. 零基础如何入门数据分析?
  3. 安装库_免费软件安装库
  4. python实现tcp通信_Python实现简易TCP通信程序
  5. 电子工程可以报考二建_电子科学与技术专业能报考二级建造师吗?
  6. python 显示RGB颜色
  7. 点云处理库pyntcloud
  8. python 获取节假日
  9. nn.Upsampling is deprecated. Use nn.functional.interpolate instead.
  10. python opencv键盘监听