之前的转账案例都是 通过test测试service和dao层
今天写一个web页面,输入转账人,收款人,金额,然后点击转账按钮完成转账。
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"
metadata-complete="false">
<servlet>
<servlet-name>springmvcservlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvcservlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
<?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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
">
<bean id="advice" class="com.bamzhy.advice.NewMyAdvice"/>
<aop:config>
<aop:aspect ref="advice">
<aop:pointcut
id="mypointcut"
expression="execution (public boolean com.bamzhy.service.UserServiceImpl.transfer(..))"/>
<aop:around method="around" pointcut-ref="mypointcut"/>
<aop:after method="finallyMethod" pointcut-ref="mypointcut"/>
</aop:aspect>
</aop:config>
<bean id="service" class="com.bamzhy.service.UserServiceImpl">
<property name="userDao" ref="userDao"/>
</bean>
<bean id="userDao" class="com.bamzhy.dao.UserDaoImpl"/>
<context:component-scan base-package="com.bamzhy"/>
<aop:aspectj-autoproxy />
<mvc:annotation-driven></mvc:annotation-driven>
</beans>
package com.bamzhy.Controller
import com.bamzhy.service.UserService
import org.springframework.context.ApplicationContext
import org.springframework.context.support.ClassPathXmlApplicationContext
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.RequestMapping
import javax.jws.WebService
import java.sql.SQLException
@Controller
public class CoreController {
@RequestMapping("/transferto")
public void test(String user1,String user2,int num,Model model) throws SQLException {
System.out.println("transfer生效了")
ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml")
UserService service = (UserService) applicationContext.getBean("service")
service.transfer(user1,user2,num)
}
}
<%--
Created by IntelliJ IDEA.
User: Bam
Date: 2018/4/2
Time: 21:53
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
</head>
<body>
<form action="${pageContext.request.contextPath}/transferto" method="post">
转账人:<input type="text" name="user1"></br>
收款人:<input type="text" name="user2"></br>
金额::<input type="text" name="num"></br>
<input type="submit" value="转账"></br>
</form>
</body>
</html>