10.10面试:SpringMVC中目前学习过的注解及功能?+怎么接受前端传递到后台的数据?

1.SpringMVC中目前学习过的注解及功能?

@RequestMapping(value="hello",method=RequestMethod.GET):注解映射请求路径,限定请求方式
@RequestParam("id")      设置地址栏参数
@PathVariable("uid")        得到地址栏@RequestMapping(value="/user/{uid}")参数 

1.1spring中注解

1.1.1声明bean(对象):

@Service 业务类型专用
@Controller web层专用
@Repository dao实现类专用
@Component 通用
@scope 用户控制bean的创建模式

1.1.2注入:

  • @Autowired 基于类型自动注入
  • @Resource 基于名称自动注入
  • @Qualifier(“userDAO”) 限定要自动注入的bean的id,一般和@Autowired联用
  • @Value 注入简单类型数据 (jdk8种+String)

2.怎么接受前端传递到后台的数据?

1.原生api接收参数:

 request.getParameter("");

2.变量接收参数:

@RequestMapping("/addUser")
    public String addUser(@RequestParam("name") String username, String password, String email,Integer age){
        System.out.println("username = " + username + ", password = " + password + ", email = " + email + ", age = " + age);
        return "hello2";
    }

3.对象接收参数


@RequestMapping("/addUsers")
    public String addUsers(User user){
        System.out.println("user = " + user);
        return "hello2";
    }

4.对于请求不同,操作不同

http:localhost:8080/user?id=1&name=jack

delete请求  服务端delete操作
post请求   新增
get   查
put   修改

猜你喜欢

转载自blog.csdn.net/qq_39773004/article/details/108990290