zoukankan      html  css  js  c++  java
  • SpringMVC_@Scope注解与RequestParam注解

    @Scope注解,设置为多例,Scope只能修饰类,如果设置为单例,只能等张三用完,李四才能用,多例的话张三创建一个,李四创建一个,互不干扰

    package cn.java.controller.front;
    
    import org.springframework.context.annotation.Scope;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    import cn.java.entity.User;
    
    @Controller
    @Scope("prototype") //设置为多例,Scope只能修饰类,如果设置为单例,只能等张三用完,李四才能用,多例的话张三创建一个,李四创建一个,互不干扰
    public class HomeController {
        @RequestMapping(value="test1.htm")
        public String test1(User user) {
            System.out.println(user);
            return "success.jsp";
        }
    }

    @AutoWired :实现依赖注入

    @RequestParam注解,当前台name改掉时,就改注解里的,defaultValue是默认值,required为true就代表必须有值传进来,false就代表没有值传进来也可以

        @RequestMapping(value="test1.htm")
        public String test1(@RequestParam(name="username",defaultValue="james",required=true) String un,@RequestParam(name="password")String pwd,@RequestParam(name="age")Integer a) {
            System.out.println("username="+un);
            System.out.println("password="+pwd);
            System.out.println("age="+a);
            return "success.jsp";
        }
  • 相关阅读:
    Python·安装扩展包的几种方法
    Arduino系列硬件资源介绍
    树莓派USB摄像头的使用
    树莓派frp服务器和客户端配置教程
    树莓派frp内网穿透
    用Windows远程桌面连接树莓派的方法
    控制窗体的位置和大小
    树霉派更换软件镜像源
    I2C的库函数应用示例
    I2C总线的Arduino库函数
  • 原文地址:https://www.cnblogs.com/lonske/p/9098111.html
Copyright © 2011-2022 走看看