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>
相关推荐
hunzi_130 分钟前
搭建商城系统
java·uni-app·php
Boilermaker19921 小时前
【Java EE】Mybatis-Plus
java·开发语言·java-ee
aramae1 小时前
C++ -- STL -- vector
开发语言·c++·笔记·后端·visual studio
xdscode2 小时前
SpringBoot ThreadLocal 全局动态变量设置
java·spring boot·threadlocal
lifallen2 小时前
Paimon 原子提交实现
java·大数据·数据结构·数据库·后端·算法
丶小鱼丶2 小时前
链表算法之【合并两个有序链表】
java·算法·链表
张先shen2 小时前
Elasticsearch RESTful API入门:全文搜索实战(Java版)
java·大数据·elasticsearch·搜索引擎·全文检索·restful
舒一笑2 小时前
PandaCoder重大产品更新-引入Jenkinsfile文件支持
后端·程序员·intellij idea
PetterHillWater3 小时前
AI编程之CodeBuddy的小试
后端·aigc
天河归来3 小时前
springboot框架redis开启管道批量写入数据
java·spring boot·redis