为了账号安全,请及时绑定邮箱和手机立即绑定

spring框架下ajax的url地址如何定位到spring对应的类

标签:
Java JQuery

通过html页面的点击事件执行ajax方法,定位到springboot的对应java类的对应方法中;

HTML代码部分

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <script th:substituteby="merchant/fragments/head::header"/>

    <!-- 组件 -->
    <link rel="stylesheet"
          href="https://a.alipayobjects.com/g/antui/antui/10.0.12/rem/??widget/dialog.css"/>

</head>
<body ontouchstart="">

<div class="am-flexbox" style="text-align:center">
    <div class="am-flexbox-item">
        欢迎使用XXXXX平台
        <br/>
        请输入以下信息完成验证
    </div>
</div>

<form class="am-list am-list-form">
    <div class="am-list-body">
        <div th:substituteby="merchant/fragments/head::input('alipayAccount','XXX账号','请输入','text',null,false)"/>
        <div th:substituteby="merchant/fragments/head::input('principalPerson','XXX姓名','请输入','text',null,false)"/>
        <div th:substituteby="merchant/fragments/head::input('principalMobile','XXX手机','请输入','text',null,false)"/>
        <div th:substituteby="merchant/fragments/head::input('certNo','XXX身份证号','请输入','text',null,false)"/>
    </div>
    <button type="button" class="am-button" **onclick="confirmID()"** style="background-color:rgba(63, 164, 237, 1);position:fixed;bottom: 0px;width: 100%;">确认</button>

    <script >
        function confirmID(){
            ap.showLoading({
                content: '执行中'
            });
            var form=$('.am-list-form').serializeArray();
            console.log(form);
            AJAX({
                type:'POST',
                url:'/rest/merchant/validate.json',
                data:form,
                dataType:'json',
                success: function(data){
                    if (data.status != 'OK') {
                        alert("验证失败,请检查输入项");
                        ap.hideLoading();
                        return;
                    }
                    $("#dialog [name='content']").html('验证成功');
                    ap.hideLoading();
                    window.location.href='/merchant/signStepOne';
                },
                error: function(e){
                    ap.hideLoading();
                    console.log(e);
                    $("#dialog [name='content']").html(e.responseJSON.message);
                    $('#dialog').show();
                }
            });
        }
    </script>
</form>
</body>
</html>

后台springboot框架的代码部分;


package com.controller;

@RestController//标注此类是一个控制器类
@RequestMapping("/rest/merchant")//RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上。用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径
public class MerchantH5RestController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(MerchantH5RestController.class);

    @Value("${qrcode.storeManage}")//在spring 3.0中,可以通过使用@value,对一些如xxx.properties文件中的文件,进行键值对的注入
    private String              qrcodeStoreManage;

    @RequestMapping(value = "/validate.json", method = { RequestMethod.POST, RequestMethod.GET })
    public HttpResult validate(HttpServletRequest request, HttpServletResponse response,@RequestParam String alipayAccount) {
        //url会根据@RequestMapping先匹配到class类上的字符串,然后再匹配到方法上的字符串,会进入到这个方法中继续执行
        //代码片段
    }

}
点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消