报错 Request method 'GET' not supported
$(function(){
var listUrl = '/o2o/productadmin/getproductcategorylist';
var addUrl = '/o2o/productadmin/addproductcategorys';
getList();
function getList(){
$.getJSON(
listUrl,
function(data){
console.log(data.data);
if(data.success){
var datalist = data.data;
$('.product-category-wrap').html('');
var temphtml='';
datalist.map(function (item,index){
temphtml += '<div class="row row-product-category now">'
+'<div class="col-33 product-category-name">'
+ item.productCategoryName
+'</div>'
+'<div class="col-33">'
+item.priority
+'</div><div class="col-33" ><a href="#" class="button delete" data-id="'
+item.productCategoryId
+'">删除</a></div>'
+'</div>';
});
$('.product-category-wrap').append(temphtml);
}
}
);
}
// 新增添加的输入项
$('#new').click(function () {
var tempHTML = '<div class="row row-product-category temp"><div class="col-33">' +
'<input class="category-input category" type="text" placeholder="分类名"></div>' +
'<div class="col-33"><input class="category-input priority" type="number" placeholder="优先级"></div>' +
'<div class="col-33"><a href="#" class="button delete">删除</a></div></div>';
// 追加
$('.product-category-wrap').append(tempHTML);
});
$('#submit').click(function(){
var tempArr = $('.temp');
var productCategoryList = [];
tempArr.map(function(item,index){
var tempObj = {};
tempObj.productCategoryName = $(index).find('.category').val();
tempObj.priority = $(index).find('.priority').val();
if(tempObj.productCategoryName != null && tempObj.priority != null){
productCategoryList.push(tempObj);
}
});
console.log(JSON.stringify(productCategoryList));
$.ajax({
url:addUrl,
type:'POST',
date:JSON.stringify(productCategoryList),
contentType:'application/json;character:utf-8',
success:function(data){
if(data.success){
$.toast('提交成功');
getList();
}else{
$.toast('提交失败');
}
}
});
});
});
package com.myk.o2o.web.productadmin;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.myk.o2o.dto.ProductCategoryExecution;
import com.myk.o2o.dto.Result;
import com.myk.o2o.entity.ProductCategory;
import com.myk.o2o.entity.Shop;
import com.myk.o2o.enums.ProductCategoryStateEnum;
import com.myk.o2o.exceptions.ProductCategoryOperationException;
import com.myk.o2o.service.ProductCategoryService;
import com.myk.o2o.util.HttpServletRequestUtil;
@Controller
@RequestMapping("/productadmin")
public class ProductManagentController {
@Autowired
private ProductCategoryService productCategoryService;
@RequestMapping(value="/getproductcategorylist",method=RequestMethod.GET)
@ResponseBody
private Result<List<ProductCategory>> getProductCategoryList(HttpServletRequest request){
Shop shop = (Shop) request.getSession().getAttribute("currentShop");
List<ProductCategory> list = new ArrayList<ProductCategory>();
if (shop != null && shop.getShopId() > 0) {
list = productCategoryService.getProductCategoryList(shop.getShopId());
return new Result<List<ProductCategory>>(true,list);
}else {
ProductCategoryStateEnum ps = ProductCategoryStateEnum.INNER_ERROR;
return new Result<List<ProductCategory>>(false,ps.getState(),ps.getStateInfo());
}
}
@RequestMapping(value="/addproductcategorys",method=RequestMethod.POST,produces = "application/json;character:utf-8")
@ResponseBody
private Map<String ,Object> addProductCategorys(@RequestBody List<ProductCategory> productCategoryList,HttpServletRequest request){
Map<String ,Object> modelMap = new HashMap<String, Object>();
Shop currentShop = (Shop) request.getSession().getAttribute("currentShop");
System.out.println(productCategoryList.size());
for (ProductCategory productCategory : productCategoryList) {
productCategory.setShopId(currentShop.getShopId());
}
if (productCategoryList != null && productCategoryList.size() >0) {
try {
ProductCategoryExecution pe = productCategoryService.batchAddProductCategory(productCategoryList);
if (pe.getState() == ProductCategoryStateEnum.SUCCESS.getState()) {
modelMap.put("success", true);
}else {
modelMap.put("success", false);
modelMap.put("errMsg",pe.getStateInfo());
}
}catch (ProductCategoryOperationException e) {
modelMap.put("success", false);
modelMap.put("errMsg", e.toString());
return modelMap;
}
}else {
modelMap.put("success", false);
modelMap.put("errMsg", "请至少输入一个商品类别");
}
return modelMap;
}
}
17
收起
正在回答 回答被采纳积分+1
1回答
4. SSM到Spring Boot入门与综合实战
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星