zoukankan      html  css  js  c++  java
  • Spring 数据传入

    表单传入

             前端代码:

    <form method="POST" id="user_login_submit">
                                    <div class="form-group">
                                        <label for="email">E-Mail Address</label>
                                        <input id="email" type="email" class="form-control" name="email" value="" required autofocus>
                                    </div>
    
                                    <div class="form-group">
                                        <label for="password">Password
                                            <a href="forgot.html" class="float-right">
                                                Forgot Password?
                                            </a>
                                        </label>
                                        <input id="password" type="password" class="form-control" name="password" required data-eye>
                                    </div>
    
                                    <div class="form-group">
                                        <label>
                                            <input type="checkbox" name="remember"> Remember Me
                                        </label>
                                    </div>
    
                                    <div class="form-group no-margin">
                                        <button id="login_btn" type="submit" class="btn btn-primary btn-block">
                                            Login
                                        </button>
                                    </div>
                                    <div class="margin-top20 text-center">
                                        Don't have an account? <a href="register.html">Create One</a>
                                    </div>
                                </form>
    $(function () {
        $("#user_login_submit").submit(function () {
            $.ajax({
                url: "/bengmall/login",
                type: "post",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                success: function (data) {
                    console.log("提交成功");
                },
                error: function (data) {
                    alert("登录過程中出現錯誤!"+data.result["result"].message);
                }
            })
        });
    });

             前端中传入了一个name 为 email , 一个为 password , 后端使用了一个类来接收数据

    @RequestMapping(value = "/login")
        public String login(User user, HttpServletRequest request, HttpServletResponse response) {
    
        ... 
    
    }
    public class User
    {
        private String email;
        private  String password;
    
        public String getEmail() {
            return email;
        }
    
        public void setEmail(String email) {
            this.email = email;
        }
    
        public String getPassword() {
            return password;
        }
    
        public void setPassword(String password) {
            this.password = password;
        }
    }

        

    URL 路径

             当传递一些不重要的数据时,只是为了查询使用时,可以通过URL 路径中放置参数查询。

    @PathVariable

      1 //http://weibo.com/user1,http://weibo.com/user2
      2 @RequestMapping("/usermanager/{username}")
      3 public String userManager(@PathVariable("username")String name )
      4 {
      5     return "usermanager";
      6 }
      7 

    @RequestParam

      1    // http://localhost:8080/springmvc/hello/101?param1=10&param2=20
      2    public String getDetails(
      3            @RequestParam(value="param1", required=true) String param1,
      4            @RequestParam(value="param2", required=false) String param2){
      5         ...
      6    }

    参考资料:

    1.https://blog.csdn.net/u011410529/article/details/66974974

  • 相关阅读:
    iphone4 wifi超时设置修改
    siteminder sso agent 初探
    [读书]35前要掌握的66种基本能力序
    Secrets of Successful Project Management
    成功项目管理的秘密
    一位乞丐给我上的MBA课程
    [读书]35前要掌握的66种基本能力第2节
    简单,有规律
    网盘使用手记
    更好地领导一个项目的诀窍
  • 原文地址:https://www.cnblogs.com/Benjious/p/9877050.html
Copyright © 2011-2022 走看看