springboot整合dwr

1、引入pom

org.directwebremoting

dwr

3.0.2-RELEASE

2、dwr.xml东西移动到java

后台服务(@RemoteProxy @RemoteMethod)

bash 复制代码
public interface DemoServiceI {
    public String hello();

    public String echo(String string) ;
}
@Service("DemoService")
@RemoteProxy(name = "DemoService")
public class DemoServiceImpl implements DemoServiceI{
    // 这里也可以使用 @Autowired 注入依赖的其他服务

    @RemoteMethod
    public String hello() {
        return "hello";
    }

    @RemoteMethod
    public String echo(String string) {
        return string;
    }
}
3、配置DwrSpringServlet 

```bash
@Configuration
public class DwrConfig {
    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        DwrSpringServlet servlet = new DwrSpringServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(servlet, "/dwr/*");
        registrationBean.addInitParameter("debug", "true");
        return registrationBean;
    }



}
复制代码
4、xml扫描

```bash
<?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:dwr="http://www.directwebremoting.org/schema/spring-dwr"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd">
 
    <dwr:annotation-config/>
 
    <dwr:annotation-scan scanRemoteProxy="false" base-package="com.aa.dwr"/>
 
    <dwr:configuration/>
</beans>
	<!-- 如果有类型转换的 -->
	<dwr:configuration>
		<dwr:convert type="bean" class="com.UnionOrderType">
	 </dwr:convert>
	</dwr:configuration>

4、js中引入

bash 复制代码
<html>
<head>
    <title></title>
    <script type='text/javascript' src='/dwr/engine.js'></script>
    <script type='text/javascript' src='/dwr/interface/DemoService.js'></script>
</head>
hello
<script>
    DemoService.echo('测试', function (str) {
        alert(str);
    });
</script>
</html>
相关推荐
好大哥呀1 分钟前
Java 中的 Spring 框架
java·开发语言·spring
计算机毕设指导61 分钟前
基于微信小程序技术校园拼车系统【源码文末联系】
java·spring boot·mysql·微信小程序·小程序·tomcat·maven
大道之简2 分钟前
SpringBoot自定义链路追踪
java·spring boot·spring
Charlie_lll3 分钟前
LibreOffice 实现 Word 转 PDF
java·spring boot·pdf·word
hhzz3 分钟前
Springboot项目中使用EasyPOI操作Excel(详细教程系列4/4)
java·spring boot·后端·spring·excel·poi·easypoi
星火开发设计8 分钟前
表达式与语句:C++ 程序的执行逻辑基础
java·开发语言·c++·学习·知识·表达式
计算机毕设指导69 分钟前
基于微信小程序求职招聘-兼职管理系统【源码文末联系】
java·spring boot·微信小程序·小程序·tomcat·maven·求职招聘
小白不会Coding13 分钟前
一文讲清楚JVM字节码文件的组成
java·jvm·字节码文件
深念Y19 分钟前
IDEA下载JDK慢的真相:权限、DNS与CDN的解析
java·ide·intellij-idea
Remember_99320 分钟前
【数据结构】二叉树:从基础到应用全面解析
java·数据结构·b树·算法·leetcode·链表