页面
<html>
<head>
<meta charset="UTF-8">
<link href="media/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="media/css/login.css" rel="stylesheet" type="text/css"/>
</head>
<body class="login">
<div class="content">
<h3 class="form-title">商品录入</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="price" id="price">
</div>
</div>
<div class="form-group">
<label class="control-label">商品描述</label>
<div>
<input class="form-control" type="text" name="description" id="description">
</div>
</div>
<div class="form-group">
<label class="control-label">图片</label>
<div>
<input class="form-control" type="text" name="imgUrl" id="imgUrl">
</div>
</div>
<div class="form-group">
<label class="control-label">库存</label>
<div>
<input class="form-control" type="text" name="stock" id="stock">
</div>
</div>
<div class="btn-cont">
<button class="btn blue" id="createItem" type="submit">
提交
</button>
</div>
</div>
</body>
<script src="media/js/jquery-1.10.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
$("#createItem").on("click",function(){
var title = $("#title").val();
var price = $("#price").val();
var description = $("#description").val();
var imgUrl = $("#imgUrl").val();
var stock = $("#stock").val();
if(title == null || title == ""){
alert("商品名不能为空");
return false;
}
if(price == null || price == ""){
alert("价格不能为空");
return false;
}
if(description == null || description == ""){
alert("描述不能为空");
return false;
}
if(imgUrl == null || imgUrl == ""){
alert("图片不能为空");
return false;
}
if(stock == null || stock == ""){
alert("库存不能为空");
return false;
}
$.ajax({
type:"POST",
contentType:"application/x-www-form-urlencoded",
url:"http://127.0.0.1:8090/item/createItem",
xhrFields:{withCredentials:true},
data:{
"title":title,
"price":price,
"description":description,
"imgUrl":imgUrl,
"stock":stock
},
success:function(data){
if(data.status == "success"){
alert("录入成功");
}else{
alert("录入失败,失败原因:"+data.data.errMsg);
}
},
error:function(data){
alert("录入失败,原因是:"+data.responseText);
}
});
return false;
});
})
</script>
</html>
Controller
@Controller("item")
@RequestMapping("/item")
@CrossOrigin(origins= {"*"},allowCredentials="true")
public class ItemController extends BaseController{
@Autowired
private ItemService itemService;
@RequestMapping(value = "/createItem",method = {RequestMethod.POST},consumes = {CONSTANT_TYPE_FORMED})
@ResponseBody
public CommonReturnType createItem(@RequestParam(name = "title") String title,
@RequestParam(name = "price") BigDecimal price,
@RequestParam(name = "description") String description,
@RequestParam(name = "sales") Integer sales,
@RequestParam(name = "imgUrl") String imgUrl,
@RequestParam(name = "stock") Integer stock
) throws BusinessException {
ItemVo itemVo = null;
try {
ItemModel itemModel = new ItemModel();
itemModel.setTitle(title);
itemModel.setPrice(price);
itemModel.setStock(stock);
itemModel.setDescription(description);
itemModel.setSales(sales);
itemModel.setImgUrl(imgUrl);
ItemModel model = itemService.createItem(itemModel);
itemVo = converVOFromItemModel(model);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return CommonReturnType.create(itemVo);
}
private ItemVo converVOFromItemModel(ItemModel itemModel) {
if(itemModel == null) {
return null;
}
ItemVo itemVo = new ItemVo();
BeanUtils.copyProperties(itemModel, itemVo);
return itemVo;
}
}
页面和Controller都是复制的User的,进不了断点,也没思路怎么排查。各位大佬给看看有没有遇到过这样的问题。
慕斯4360584
慕慕5436299
相关分类