一、处理提交数据
1.1 提交的域名称和处理方法的参数名一致
提交数据 : http://localhost:8080/Springmvc_04_controller_war_exploded/user/t1?name=Bob
处理方法:
package controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/user")
public class UserController {
//localhost:8080/项目名/user/t1?name = XXX;
@GetMapping("/t1")
public String test1(String name, Model model){
//1.接收前端参数
System.out.println(name);
//2.将返回的结果传递给前端
model.addAttribute("msg",name);
//3.跳转视图
return "hello";
}
}
跳转到hello.jsp页面,并输出:Bob
1.2 提交的域名称和处理方法的参数名不一致
提交数据 : http://localhost:8080/Springmvc_04_controller_war_exploded/user/t1?username=Bob
处理方法:
package