springboot接收多对象_springboot 提交表单和图片,后台对象接收

springboot 提交表单和图片,后台对象接收

2018-09-21 10:53:12   作者:MangoCool   来源:MangoCool

简述:springboot项目中,前端表单提交数据,其中包括图片,后台以对象一并接收,然后直接入库,就这么简单的需求。

直接上代码:

CompanyInfoController 控制器:

package net.olym.symailp.website.controller;

import net.olym.symailp.core.util.AjaxUtils;

import net.olym.symailp.core.util.CommonResponseMap;

import net.olym.symailp.website.model.CompanyModel;

import net.olym.symailp.website.service.CompanyInfoService;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

@RestController

@RequestMapping("/webmgr/companys")

public class CompanyInfoController {

private static final Log LOG = LogFactory.getLog(CompanyInfoController.class);

@Autowired

HttpServletRequest request;

@Autowired

HttpServletResponse response;

@Autowired

CompanyInfoService companyInfoService;

@RequestMapping(value="/info", method = RequestMethod.GET)

public void getCompanyInfo() {

CommonResponseMap dataMap = new CommonResponseMap();

try {

CommonResponseMap retMap = companyInfoService.getCompanyInfo();

dataMap.putAll(retMap);

} catch (Exception e) {

LOG.error(e.getMessage(), e);

dataMap.error();

} finally {

AjaxUtils.sendAjaxForObject(response, dataMap);

}

}

@RequestMapping(value="/{id}", method = RequestMethod.POST)

public void updateCompanyInfo(CompanyModel company) {

CommonResponseMap dataMap = new CommonResponseMap();

try {

CommonResponseMap retMap = companyInfoService.updateCompanyInfo(company);

dataMap.putAll(retMap);

} catch (Exception e) {

LOG.error(e.getMessage(), e);

dataMap.error();

} finally {

AjaxUtils.sendAjaxForObject(response, dataMap);

}

}

}

CompanyInfoService 接口:

package net.olym.symailp.website.service;

import net.olym.symailp.core.util.CommonResponseMap;

import net.olym.symailp.website.model.CompanyModel;

public interface CompanyInfoService {

CommonResponseMap getCompanyInfo() throws Exception;

CommonResponseMap updateCompanyInf

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值