正在回答 回答被采纳积分+1
PathUtil
public class PathUtil {
public static String seperator =System.getProperty("file.separator");
public static String getImgBasePath() {
String os = System.getProperty("os.name");
String basePath="";
if(os.toLowerCase().startsWith("win")) {
basePath="/Intel/image/";
}else {
basePath="D:/Projectev/image/";
}
basePath=basePath.replace("/",seperator);
return basePath;
}
public static String getShopImagePath(long shopId) {
String imagePath="upload/item/shop/"+shopId+"/";
return imagePath.replace("/", seperator);
}
}
严重: Servlet.service() for servlet [spring-dispatcher] in context with path [/oyuan] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at com.imooc.oyuan.web.shopadmin.ShopManagementController.registerShop(ShopManagementController.java:128)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:528)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:810)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:835)
4月 28, 2020 3:59:07 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [spring-dispatcher] in context with path [/oyuan] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at com.imooc.oyuan.web.shopadmin.ShopManagementController.registerShop(ShopManagementController.java:128)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:528)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:810)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:835)
JS代码
$(function(){
var shopId = getQueryString('shopId');
var isEdit = shopId ? true : false;
var initUrl = '/oyuan/shopadmin/getshopinitinfo';
// 注册店铺的URL
var registerShopUrl ='/oyuan/shopadmin/registershop';
// 编辑店铺前需要获取店铺信息,这里为获取当前店铺信息的URL
var shopInfoUrl = "/oyuan/shopadmin/getshopbyid?shopId=" + shopId;
var editShopUrl = '/oyuan/shopadmin/modifyshop';
if(!isEdit){
getShopInitInfo();
}else{
getShopInfo(shopId);
}
function getShopInfo(shopId) {
$.getJSON(shopInfoUrl, function(data) {
if (data.success) {
// 若访问成功,则依据后台传递过来的店铺信息为表单元素赋值
var shop = data.shop;
$('#shop-name').val(shop.shopName);
$('#shop-addr').val(shop.shopAddr);
$('#shop-phone').val(shop.phone);
$('#shop-desc').val(shop.shopDesc);
// 给店铺类别选定原先的店铺类别值
var shopCategory = '<option data-id="'
+ shop.shopCategory.shopCategoryId + '" selected>'
+ shop.shopCategory.shopCategoryName + '</option>';
var tempAreaHtml = '';
// 初始化区域列表
data.areaList.map(function(item, index) {
tempAreaHtml += '<option data-id="' + item.areaId + '">'
+ item.areaName + '</option>';
});
$('#shop-category').html(shopCategory);
// 不允许选择店铺类别
$('#shop-category').attr('disabled', 'disabled');
$('#area').html(tempAreaHtml);
// 给店铺选定原先的所属的区域
$("#area option[data-id='" + shop.area.areaId + "']").attr(
"selected", "selected");
}
});
}
// 取得所有二级店铺类别以及区域信息,并分别赋值进类别列表以及区域列表
function getShopInitInfo(){
$.getJSON(initUrl,function(data){
if(data.success){
var tempHtml='';
var tempAreaHtml='';
data.shopCategoryList.map(function(item, index) {
tempHtml += '<option data-id="' + item.shopCategoryId
+ '">' + item.shopCategoryName + '</option>';
});
data.areaList.map(function(item, index) {
tempAreaHtml += '<option data-id="' + item.areaId + '">'
+ item.areaName + '</option>';
});
$('#shop-category').html(tempHtml);
$('#area').html(tempAreaHtml);
}
});
}
$('#submit').click(function(){
var shop={};
if(isEdit){
shop.shopId=shopId;
}
shop.shopName=$('#shop-name').val();
shop.shopAddr=$('#shop-addr').val();
shop.phone=$('#shop-phone').val();
shop.shopDesc=$('#shop-desc').val();
shop.shopCategory =
{shopCategoryId : $('#shop-category').find('option').not(function() {
return !this.selected;
}).data('id')
};
shop.area = {
areaId : $('#area').find('option').not(function() {
return !this.selected;
}).data('id')
};// 获取上传的图片文件流
var shopImg = $('#shop-img')[0].files[0];
// 生成表单对象,用于接收参数并传递给后台
var formData = new FormData();
// 添加图片流进表单对象里
formData.append('shopImg', shopImg);
// 将shop json对象转成字符流保存至表单对象key为shopStr的的键值对里
formData.append('shopStr', JSON.stringify(shop));
var verifyCodeActual = $('#j_captcha').val();
if (!verifyCodeActual) {
$.toast('请输入验证码!');
return;
}
formData.append('verifyCodeActual', verifyCodeActual);
// 将数据提交至后台处理相关操作
$.ajax({
url :(isEdit?editShopUrl: registerShopUrl),
type : 'POST',
data : formData,
contentType : false,
processData : false,
cache : false,
success : function(data) {
if (data.success) {
$.toast('提交成功!');
}else{
$.toast('提交失败!'+data.errMsg);
}
$('#captcha_img').click();
}
});
});
})
public class ImageUtil {
private static String basePath=Thread.currentThread().getContextClassLoader().getResource("").getPath();
private static final SimpleDateFormat sDateFormat=new SimpleDateFormat("yyyMMddHHmmss");
private static final Random r= new Random();
private static Logger logger = LoggerFactory.getLogger(ImageUtil.class);
public static File transferCommonsMultipartFileToFile(CommonsMultipartFile cFile) {
File newFile = new File(cFile.getOriginalFilename());
try {
cFile.transferTo(newFile);
} catch (IllegalStateException e) {
logger.error(e.toString());
e.printStackTrace();
} catch (IOException e) {
logger.error(e.toString());
e.printStackTrace();
}
return newFile;
}
public static String generateThumbnail(InputStream thumbnailInputStream,String fileName,String targetAddr) {
// 获取不重复的随机名
String realFileName = getRandomFileName();
// 获取文件的扩展名如png,jpg等
String extension = getFileExtension(fileName);
// 如果目标路径不存在,则自动创建
makeDirPath(targetAddr);
// 获取文件存储的相对路径(带文件名)
String relativeAddr = targetAddr + realFileName + extension;
logger.debug("current relativeAddr is :" + relativeAddr);
// 获取文件要保存到的目标路径
File dest = new File(PathUtil.getImgBasePath() + relativeAddr);
logger.debug("current complete addr is :" + PathUtil.getImgBasePath() + relativeAddr);
try {
Thumbnails.of(thumbnailInputStream).size(200, 200)
.watermark(Positions.BOTTOM_RIGHT, ImageIO.read(new File(basePath + "/watermark.jpg")), 0.25f)
.outputQuality(0.8f).toFile(dest);
} catch (IOException e) {
logger.error(e.toString());
e.printStackTrace();
}
return relativeAddr;
}
private static void makeDirPath(String targetAddr) {
// TODO Auto-generated method stub
String realFileParentPath = PathUtil.getImgBasePath() + targetAddr;
File dirPath = new File(realFileParentPath);
if (!dirPath.exists()) {
dirPath.mkdirs();
}
}
private static String getFileExtension(String fileName) {
// TODO Auto-generated method stub
return fileName.substring(fileName.lastIndexOf("."));
}
public static String getRandomFileName() {
// 获取随机的五位数
int rannum = r.nextInt(89999) + 10000;
String nowTimeStr = sDateFormat.format(new Date());
return nowTimeStr + rannum;
}
public static void main(String[] args) throws IOException {
String basePath=Thread.currentThread().getContextClassLoader().getResource("").getPath();
Thumbnails.of(new File("/Intel/image/xiaogou.jpg")).size(200, 200).watermark(Positions.BOTTOM_RIGHT, ImageIO.read(new File(basePath+ "watermark.jpg")),
0.25f).outputQuality(0.8f).toFile("/Intel/image/xiaogounew.jpg");
}
/**
* storePath是文件的路径还是目录的路径, 如果storePath是文件路径则删除该文件,
* 如果storePath是目录路径则删除该目录下的所有文件
*
* @param storePath
*/
public static void deleteFileOrPath(String storePath) {
File fileOrPath = new File(PathUtil.getImgBasePath() + storePath);
if (fileOrPath.exists()) {
if (fileOrPath.isDirectory()) {
File files[] = fileOrPath.listFiles();
for (int i = 0; i < files.length; i++) {
files[i].delete();
}
}
fileOrPath.delete();
}
}
}
public class ShopServiceImpl implements ShopService {
@Autowired
private ShopDao shopDao;
@Transactional
public ShopExecution addShop(Shop shop, InputStream shopImgInputStream,String fileName) {
if (shop == null) {
return new ShopExecution(ShopStateEnum.NULL_SHOP);
}
try {
// 给店铺信息赋初始值
shop.setEnableStatus(0);
shop.setCreateTime(new Date());
shop.setLastEditTime(new Date());
// 添加店铺信息
int effectedNum = shopDao.insertShop(shop);
if (effectedNum <= 0) {
throw new ShopOperationException("店铺创建失败");
} else {
if (shopImgInputStream != null) {
// 存储图片
try {
addShopImg(shop, shopImgInputStream,fileName);
} catch (Exception e) {
throw new ShopOperationException("addShopImg error:" + e.getMessage());
}
// 更新店铺的图片地址
effectedNum = shopDao.updateShop(shop);
if (effectedNum <= 0) {
throw new ShopOperationException("更新图片地址失败");
}
}
}
} catch (Exception e) {
throw new ShopOperationException("addShop error:" + e.getMessage());
}
return new ShopExecution(ShopStateEnum.CHECK,shop);
}
private void addShopImg(Shop shop, InputStream shopImgInputStream,String fileName) {
// TODO Auto-generated method stub
// 获取shop图片目录的相对值路径
String dest = PathUtil.getShopImagePath(shop.getShopId());
String shopImgAddr = ImageUtil.generateThumbnail(shopImgInputStream,fileName,dest);
shop.setShopImg(shopImgAddr);
}
public Shop getByShopId(long shopId) {
return shopDao.queryByShopId(shopId);
}
public ShopExecution modifyShop(Shop shop, InputStream shopImgInputStream, String fileName)
throws ShopOperationException {
if (shop == null || shop.getShopId() == null) {
return new ShopExecution(ShopStateEnum.NULL_SHOP);
} else {
// 1.判断是否需要处理图片
try{
if(shopImgInputStream != null && fileName != null && !"".equals(fileName)){
Shop tempShop = shopDao.queryByShopId(shop.getShopId());
if(tempShop.getShopImg() != null){
ImageUtil.deleteFileOrPath(tempShop.getShopImg());
}
addShopImg(shop, shopImgInputStream, fileName);
}
// 2.更新店铺信息
shop.setLastEditTime(new Date());
int effectedNum = shopDao.updateShop(shop);
if (effectedNum <= 0) {
return new ShopExecution(ShopStateEnum.INNER_ERROR);
} else {
shop = shopDao.queryByShopId(shop.getShopId());
return new ShopExecution(ShopStateEnum.SUCCESS, shop);
}
} catch (Exception e) {
throw new ShopOperationException("modifyShop error:" + e.getMessage());
}
}
}
}
@Controller
@RequestMapping("/shopadmin")
public class ShopManagementController {
@Autowired
private ShopService shopService;
@Autowired
private ShopCategoryService shopCategoryService;
@Autowired
private AreaService areaService;
@RequestMapping(value = "/getshopbyid", method = RequestMethod.GET)
@ResponseBody
private Map<String, Object> getShopById(HttpServletRequest request) {
Map<String, Object> modelMap = new HashMap<String, Object>();
Long shopId = HttpServletRequestUtil.getLong(request, "shopId");
if (shopId > -1) {
try {
Shop shop = shopService.getByShopId(shopId);
List<Area> areaList = areaService.getAreaList();
modelMap.put("shop", shop);
modelMap.put("areaList", areaList);
modelMap.put("success", true);
} catch (Exception e) {
modelMap.put("success", false);
modelMap.put("errMsg", e.toString());
}
} else {
modelMap.put("success", false);
modelMap.put("errMsg", "empty shopId");
}
return modelMap;
}
@RequestMapping(value="/getshopinitinfo",method = RequestMethod.GET)
@ResponseBody
private Map<String,Object> getShopInitInfo(){
Map<String, Object> modelMap = new HashMap<String, Object>();
List<ShopCategory> shopCategoryList = new ArrayList<ShopCategory>();
List<Area> areaList = new ArrayList<Area>();
try {
shopCategoryList = shopCategoryService.getShopCategoryList(new ShopCategory());
areaList = areaService.getAreaList();
modelMap.put("shopCategoryList", shopCategoryList);
modelMap.put("areaList", areaList);
modelMap.put("success", true);
} catch (Exception e) {
modelMap.put("success", false);
modelMap.put("errMsg", e.getMessage());
}
return modelMap;
}
@RequestMapping(value="/registershop",method=RequestMethod.POST)
@ResponseBody
private Map<String, Object> registerShop(HttpServletRequest request){
Map<String, Object> modelMap = new HashMap<String, Object>();
if (!CodeUtil.checkVerifyCode(request)) {
modelMap.put("success", false);
modelMap.put("errMsg", "输入了错误的验证码");
return modelMap;
}
//接受并转化相应的参数,包括店铺信息以及图片信息
String shopStr=HttpServletRequestUtil.getString(request, "shopStr");
ObjectMapper mapper=new ObjectMapper();
Shop shop=null;
try {
shop=mapper.readValue(shopStr,Shop.class);
}catch(Exception e){
modelMap.put("success",false);
modelMap.put("errMsg",e.getMessage());
return modelMap;
}
CommonsMultipartFile shopImg = null;
CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver(
request.getSession().getServletContext());
if (commonsMultipartResolver.isMultipart(request)) {
MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) request;
shopImg = (CommonsMultipartFile) multipartHttpServletRequest.getFile("shopImg");
} else {
modelMap.put("success", false);
modelMap.put("errMsg", "上传图片不能为空");
return modelMap;
}
//注册店铺
if (shop != null && shopImg != null) {
PersonInfo owner =(PersonInfo) request.getSession().getAttribute("user");
shop.setOwner(owner);
ShopExecution se;
try {
se = shopService.addShop(shop,shopImg.getInputStream(),shopImg.getOriginalFilename());
if(se.getState() == ShopStateEnum.CHECK.getState()){
modelMap.put("success",true);
@SuppressWarnings("unchecked")
List<Shop> shopList = (List<Shop>)request.getSession().getAttribute("shoplist");
if(shopList == null || shopList.size() == 0) {
shopList = new ArrayList<Shop>();
}
shopList.add(se.getShop());
request.getSession().setAttribute("shopList", shopList);
}else {
modelMap.put("success",false);
modelMap.put("errMsg",se.getStateInfo());
}
} catch (ShopOperationException e) {
modelMap.put("success",false);
modelMap.put("errMsg",e.getMessage());
} catch (IOException e) {
modelMap.put("success",false);
modelMap.put("errMsg",e.getMessage());
}
return modelMap;
}else {
modelMap.put("success", false);
modelMap.put("errMsg", "请输出店铺信息");
return modelMap;
}
}
@RequestMapping(value = "/modifyshop",method = RequestMethod.POST)
@ResponseBody
private Map<String, Object> modifyshop(HttpServletRequest request) {
Map<String, Object> modelMap = new HashMap<String, Object>();
if (!CodeUtil.checkVerifyCode(request)) {
modelMap.put("success", false);
modelMap.put("errMsg", "输入了错误的验证码");
return modelMap;
}
// 1.接收并转化相应的参数,包括店铺信息以及图片信息
String shopStr = HttpServletRequestUtil.getString(request, "shopStr");
ObjectMapper mapper = new ObjectMapper();
Shop shop = null;
try {
shop = mapper.readValue(shopStr, Shop.class);
} catch (Exception e) {
modelMap.put("success", false);
modelMap.put("errMsg", e.getMessage());
return modelMap;
}
CommonsMultipartFile shopImg = null;
CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver(
request.getSession().getServletContext());
if (commonsMultipartResolver.isMultipart(request)) {
MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) request;
shopImg = (CommonsMultipartFile) multipartHttpServletRequest.getFile("shopImg");
}
// 2.修改店铺信息
if (shop != null && shop.getShopId() != null) {
ShopExecution se;
try {
if(shopImg == null){
se = shopService.modifyShop(shop, null, null);
}else{
se = shopService.modifyShop(shop, shopImg.getInputStream(), shopImg.getOriginalFilename());
}
if(se.getState() == ShopStateEnum.SUCCESS.getState()){
modelMap.put("success",true);
}else{
modelMap.put("success", false);
modelMap.put("errMsg", se.getStateInfo());
}
} catch (ShopOperationException e){
modelMap.put("success", false);
modelMap.put("errMsg", e.getMessage());
} catch (IOException e) {
modelMap.put("success", false);
modelMap.put("errMsg", e.getMessage());
}
return modelMap;
} else {
modelMap.put("success", false);
modelMap.put("errMsg", "请输入店铺Id");
return modelMap;
}
}
/*
* private static void inputStreamToFile(InputStream ins,File file) {
* FileOutputStream os=null; try { os=new FileOutputStream(file); int
* bytesRead=0; byte[] buffer=new byte[1024];
* while((bytesRead=ins.read(buffer))!=-1) { os.write(buffer,0,bytesRead); }
* }catch(Exception e) { throw new
* RuntimeException("调用inputStreamToFile产生异常"+e.getMessage()); }finally { try {
* if(os!=null) { os.close(); } if(ins!=null) { ins.close(); }
* }catch(IOException e) { throw new
* RuntimeException("inputStreamToFile关闭io产生异常"+e.getMessage()); } } }
*/
}
相似问题
登录后可查看更多问答,登录/注册
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星