奶茶精Gaaa 2024-06-23 21:31 采纳率: 46.2%
浏览 2

解决下面错误,springboot

解决下面错误,springboot

img

img


package com.itheima.springbootquickstart.controller;

import com.itheima.springbootquickstart.pojo.Category;
import com.itheima.springbootquickstart.pojo.Result;
import com.itheima.springbootquickstart.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @PostMapping
    public Result add(@RequestBody Category category){
categoryService.add(category);
return Result.success();
    }
}

package com.itheima.springbootquickstart.service.impl;

import com.itheima.springbootquickstart.mapper.CategoryMapper;
import com.itheima.springbootquickstart.pojo.Category;
import com.itheima.springbootquickstart.service.CategoryService;
import com.itheima.springbootquickstart.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public void add(Category category) {
        //补充属性值
        category.setCreateTime(LocalDateTime.now());
        category.setUpdateTime(LocalDateTime.now());

        Map<String,Object> map = ThreadLocalUtil.get();
        Integer userId = (Integer) map.get("id");
        category.setCreateUser(userId);
        categoryMapper.add(category);
    }

    @Override
    public List<Category> list() {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer userId = (Integer) map.get("id");
        return categoryMapper.list(userId);
    }

    @Override
    public Category findById(Integer id) {
        Category c = categoryMapper.findById(id);
        return c;
    }

    @Override
    public void update(Category category) {
        category.setUpdateTime(LocalDateTime.now());
        categoryMapper.update(category);
    }

    @Override
    public void deleteById(Integer id) {
        categoryMapper.deleteById(id);
    }
}


  • 写回答

3条回答 默认 最新

  • 夜郎king 2022博客之星IT其它领域TOP 12 2024-07-04 08:42
    关注

    入参数据类型的问题,把一个字符串要求后台转数字,传过去的值是什么

    评论

报告相同问题?

问题事件

  • 创建了问题 6月23日