码迷,mamicode.com
首页 > 编程语言 > 详细

Spring Boot—09通过Form提交的映射

时间:2018-04-23 19:54:05      阅读:430      评论:0      收藏:0      [点我收藏+]

标签:code   round   映射   mda   res   none   ram   AC   pad   

package com.sample.smartmap.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sample.smartmap.controller.form.OrderPostForm;
import com.sample.smartmap.entity.User;
import com.sample.smartmap.service.UserService;
/**
 * 通过form提交的各种映射举例
 *
 */
@Controller
@RequestMapping("/javabean")
public class JavaBeanController {
    
    @Autowired UserService userService;
    
    @GetMapping(path = "/update.json")
    @ResponseBody
    public String updateUser(User user) {
        System.out.println(user.getName());
        System.out.println(user.getId());
        return "success";
    }
    
    @GetMapping(path = "/update2.json")
    @ResponseBody
    public String updateUser2(Integer id, String name) {
        System.out.println(id);
        System.out.println(name);
        return "success";
    }
    
    
    @GetMapping(path = "/update3.json")
    @ResponseBody
    public String updateUser3(@RequestParam(name="id",required=true) Integer id, String name) {
        System.out.println(id);
        System.out.println(name);
        return "success";
    }

    @PostMapping(path = "/saveOrder.json")
    @ResponseBody
    public String saveOrder( OrderPostForm form) {
        return "success";
    }
    
    @PostMapping(path = "/savejsonorder.json")
    @ResponseBody
    public String saveOrderByJson(@RequestBody User user) {
        return user.getName();
    }
    
}

Spring Boot—09通过Form提交的映射

标签:code   round   映射   mda   res   none   ram   AC   pad   

原文地址:https://www.cnblogs.com/gispathfinder/p/8921162.html

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!