@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"; }
原文地址:https://www.cnblogs.com/lonske/p/9098111.html
时间: 2024-11-14 13:54:59