第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

創(chuàng)建商品失敗,未知錯誤

debug之后發(fā)現(xiàn)代碼走到itemController層以后直接被父類的baseController的分支return出去了 分支2 這個怎么辦? 沒法進入service層就直接return了status一直是fail,前臺未知錯誤,求解

package?com.miaoshaproject.controller;

import?com.miaoshaproject.error.BusinessException;
import?com.miaoshaproject.error.EmBusinessError;
import?com.miaoshaproject.response.CommonReturnType;
import?org.springframework.http.HttpStatus;
import?org.springframework.web.bind.annotation.ExceptionHandler;
import?org.springframework.web.bind.annotation.ResponseBody;
import?org.springframework.web.bind.annotation.ResponseStatus;

import?javax.servlet.http.HttpServletRequest;
import?java.util.HashMap;
import?java.util.Map;

public?class?BaseController?{
????public?static?final?String?CONTENT_TYPE_FORMED="application/x-www-form-urlencoded";

????//定義exceptionHandler解決未被controller層吸收的exception
????@ExceptionHandler(Exception.class)
????@ResponseStatus(HttpStatus.OK)
????@ResponseBody
????public?Object?handlerException(HttpServletRequest?req,?Exception?ex){
????????CommonReturnType?commonReturnType?=?new?CommonReturnType();
????????Map<String,?Object>?responseData?=?new?HashMap<>();
????????if(ex?instanceof?BusinessException){
????????????BusinessException?businessException?=?(BusinessException)ex;
????????????responseData.put("errCode",businessException.getErrCode());
????????????responseData.put("errMsg",businessException.getErrMsg());
????????????System.out.println("打樁分支1");
????????}else?{
????????????responseData.put("errCode",?EmBusinessError.UNKNOWN_EXCEPTION.getErrCode());
????????????responseData.put("errMsg",EmBusinessError.UNKNOWN_EXCEPTION.getErrMsg());
????????????System.out.println("打樁分支2");
????????}
????????return?CommonReturnType.create(responseData,"fail");
????}
}
package?com.miaoshaproject.controller;

import?com.miaoshaproject.controller.viewobject.ItemVO;
import?com.miaoshaproject.error.BusinessException;
import?com.miaoshaproject.response.CommonReturnType;
import?com.miaoshaproject.service.ItemService;
import?com.miaoshaproject.service.model.ItemModel;
import?org.springframework.beans.BeanUtils;
import?org.springframework.beans.factory.annotation.Autowired;
import?org.springframework.stereotype.Controller;
import?org.springframework.web.bind.annotation.*;

import?java.math.BigDecimal;

@Controller("item")
@RequestMapping("/item")
@CrossOrigin(origins?=?{"*"},?allowCredentials?=?"true")
public?class?ItemController?extends??BaseController?{

????@Autowired
????private?ItemService?itemService;

????//創(chuàng)建商品的Controller
????@RequestMapping(value?=?"/create",method?=?RequestMethod.POST,consumes?=?{CONTENT_TYPE_FORMED})
????@ResponseBody
????public?CommonReturnType?createItem(@RequestParam(name?=?"title")String?title,
???????????????????????????????????????@RequestParam(name?=?"description")?String?description,
???????????????????????????????????????@RequestParam(name?=?"price")BigDecimal?price,
???????????????????????????????????????@RequestParam(name?=?"stock")Integer?stock,
???????????????????????????????????????@RequestParam(name?=?"imgUrl")String?imgUrl)?throws?BusinessException?{
????????//封裝Service請求用來創(chuàng)建商品
????????ItemModel?itemModel?=?new?ItemModel();
????????itemModel.setTitle(title);
????????itemModel.setDescroption(description);
????????itemModel.setPrice(price);
????????itemModel.setStock(stock);
????????itemModel.setImgUrl(imgUrl);
????????ItemModel?mode?=?itemService.createItem(itemModel);
????????ItemVO?itemVO?=?convertVOFromModel(mode);
????????return?CommonReturnType.create(itemVO);
????}

????private?ItemVO?convertVOFromModel(ItemModel?itemModel){
????????if(itemModel==null){
????????????return??null;
????????}
????????ItemVO?itemVO?=?new?ItemVO();
????????BeanUtils.copyProperties(itemModel,itemVO);
????????return?itemVO;
????}
}


正在回答

5 回答

感謝老哥,之前一直找不到錯誤,用你說的debug調試果然一下子就看到錯誤解決了

0 回復 有任何疑惑可以回復我~
#1

慕沐604797

請問是怎么解決的
2021-09-22 回復 有任何疑惑可以回復我~

找到bug了 在itemModel中Integer變量stock上我用了@NotBlank,應該用@NotNull才對 所以入?yún)⑿r炛苯邮?debug斷點打在BaseController中的Ex上變量有詳細的描述才定位到Bug,搞了幾個小時才搞定 銘記一生

0 回復 有任何疑惑可以回復我~
#1

慕慕0284258

謝謝老哥,我也是找了一晚上一直找不到,看了你這個發(fā)現(xiàn)我的圖片的@NotBlank放在sales上了
2020-05-15 回復 有任何疑惑可以回復我~

debug斷點從itemcontroller的


debug斷點從ItemController中的

ItemModel?mode?=?itemService.createItem(itemModel);

方法后就直接跳轉到了

InvocableHandlerMethod

這個spring類庫中的方法中去了

搞不懂!求解釋

0 回復 有任何疑惑可以回復我~

前臺代碼

<!DOCTYPE?html><html><head>????<meta?charset="utf-8"><script?src="node_modules\jquery\dist\jquery.js"?type="text/javascript"></script><link?href="node_modules\bootstrap\dist\css\bootstrap.css"style="stylesheet"?type="text/css"><link?href="static/assets/global/css/components.css"rel="stylesheet"?type="text/css"><link?href="static/assets/admin/pages/css/login.css"rel="stylesheet"?type="text/css"></head><body?class="login">????<div?class="content">?????????<h3?class="form-title">創(chuàng)建商品</h3>????????<div?class="form-group">????????????<label?class="control-label">商品名</label>????????????<div>????????????????<input?class="form-control"?type="text"?placeholder="商品名"?name="title"?id="title">????????????</div>????????</div>????????<div?class="form-group">????????????<label?class="control-label">商品描述</label>????????????<div>????????????????<input?class="form-control"?type="text"??placeholder="商品描述"?name="description"?id="description">????????????</div>????????</div>????????<div?class="form-group">????????????<label?class="control-label">價格</label>????????????<div>????????????????<input?class="form-control"?type="text"?placeholder="價格"?name="price"?id="price">????????????</div>????????</div>????????<div?class="form-group">????????????<label?class="control-label">圖片</label>????????????<div>????????????????<input?class="form-control"?type="text"?placeholder="圖片"??name="imgUrl"?id="imgUrl">????????????</div>????????</div>????????<div?class="form-group">????????????<label?class="control-label">庫存</label>????????????<div>????????????????<input?class="form-control"?type="text"?placeholder="庫存"?name="stock"?id="stock">????????????</div>????????</div>????????????????????????<div?class="form-actions">????????????<button?class="btn?blue"?type="submit"?id="create">提交創(chuàng)建</button>????????</div>????</div>????</body><script?type="text/javascript">????jQuery(document).ready(function(){????????$("#create").on("click",function(){????????????var?title?=?$("#title").val();????????????var?description?=?$("#description").val();????????????var?price?=?$("#price").val();????????????var?imgUrl?=?$("#imgUrl").val();????????????var?stock?=?$("#stock").val();????????????if(title==null?||?title?==?""){????????????????alert("商品名不能為空!");????????????????return?false;????????????}????????????if(description==null?||?description?==?""){????????????????alert("描述不能為空!");????????????????return?false;????????????}????????????if(price==null?||?price?==?""){????????????????alert("價格不能為空!");????????????????return?false;????????????}????????????if(imgUrl==null?||?imgUrl?==?""){????????????????alert("圖片url不能為空!");????????????????return?false;????????????}????????????if(stock==null?||?stock?==?""){????????????????alert("庫存不能為空!");????????????????return?false;????????????}????????????$.ajax({????????????????type:"POST",????????????????contentType:"application/x-www-form-urlencoded",????????????????url:"http://localhost:8080/item/create",????????????????data:{????????????????????"title":title,????????????????????"description":description,????????????????????"price":price,????????????????????"imgUrl":imgUrl,????????????????????"stock":stock????????????????},????????????????????xhrFields:{withCredentials:true},????????????????success:function(data){????????????????????if(data.status?=="success"){????????????????????????alert("創(chuàng)建成功")????????????????????}else{????????????????????????alert("創(chuàng)建失敗了"+data.data.errMsg)????????????????????}????????????????},????????????????error:function(data){????????????????????alert("創(chuàng)建失敗"+data.responseText)????????????????}????????????});????????????return?false;????????})????})????</script></html>


0 回復 有任何疑惑可以回復我~

2019-12-15 01:08:10.425? INFO 11728 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]? ? ? ?: Initializing Spring DispatcherServlet 'dispatcherServlet'

2019-12-15 01:08:10.426? INFO 11728 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet? ? ? ? : Initializing Servlet 'dispatcherServlet'

2019-12-15 01:08:10.432? INFO 11728 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet? ? ? ? : Completed initialization in 6 ms

2019-12-15 01:08:10.576? INFO 11728 --- [nio-8080-exec-1] com.alibaba.druid.pool.DruidDataSource? ?: {dataSource-1} inited

打樁分支2

這是前臺請求發(fā)送后,IDEA后臺的堆棧信息?

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

創(chuàng)建商品失敗,未知錯誤

我要回答 關注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號