-
SpringMVC的几种返回方式
- package com.boventech.learning.controller;
-
- import java.util.HashMap;
- import java.util.Map;
-
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.servlet.ModelAndView;
-
- import com.boventech.learning.entity.User;
-
- @Controller
- @RequestMapping("/MVCReturn")
- public class SpringMVCReturnController {
-
- @RequestMapping(value="/index1",method=RequestMethod.GET)
- public ModelAndView index(){
- ModelAndView modelAndView = new ModelAndView("/user/index");
- modelAndView.addObject("name", "xxx");
- return modelAndView;
- }
-
-
- @RequestMapping(value="/index2",method=RequestMethod.GET)
- public ModelAndView index2(){
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.addObject("name", "xxx");
- modelAndView.setViewName("/user/index");
- return modelAndView;
- }
-
-
-
- @RequestMapping(value="/index3",method=RequestMethod.GET)
- public Map<String, String> index3(){
- Map<String, String> map = new HashMap<String, String>();
- map.put("1", "1");
-
- return map;
- }
-
-
-
-
- @RequestMapping(value="/index4",method = RequestMethod.GET)
- public String index(Model model) {
- String retVal = "user/index";
- User user = new User();
- user.setName("XXX");
- model.addAttribute("user", user);
- return retVal;
- }
-
-
- @RequestMapping(value = "/valid", method = RequestMethod.GET)
- @ResponseBody
- public String valid(@RequestParam(value = "userId", required = false) Integer userId,
- @RequestParam(value = "name") String name) {
- return String.valueOf(true);
- }
-
-
-
- @RequestMapping(method=RequestMethod.GET)
- public void index5(){
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.addObject("xxx", "xxx");
- }
-
-
-
-
- }
-
相关阅读:
内网穿透之frp X
python图形界面开发工具之PySimpleGUI X
API 接口开发调试工具之ApiPost X
分布式对象存储只FDFS X
开发者工具 X
Tornado框架之应用安全(四) X
MySQL数据库设计规范(新) X
Tornado框架之项目部署(六) X
PHP之soap X
python命令行工具之Click X
-
原文地址:https://www.cnblogs.com/jtlgb/p/5972978.html
Copyright © 2020-2023
润新知