怎么解决springboot这个问题?
![img](
package com.itheima.springbootquickstart.service.impl;
import com.itheima.springbootquickstart.mapper.CategoryMapphttps://img-mid.csdnimg.cn/release/static/image/mid/ask/06a30f66ece04c63b25e4949153a3f6f.png "#left")
er;
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.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);
}
package com.itheima.springbootquickstart.service;
import com.itheima.springbootquickstart.pojo.Category;
public interface CategoryService {
// 新增分类
void add(Category category);
}
package com.itheima.springbootquickstart.pojo;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class Category {
private Integer id;//主键ID
private String categoryName;//分类名称
private String categoryAlias;//分类别名
private Integer createUser;//创建人ID
private LocalDateTime createTime;//创建时间
private LocalDateTime updateTime;//更新时间
}
package com.itheima.springbootquickstart.mapper;
import com.itheima.springbootquickstart.pojo.Category;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface CategoryMapper {
// 新增
@Insert("insert into category(category_name, category_alias,create_user,create_time,update_time)"+
"values(#{categoryName}, #{categoryAlias},#{createUser},#{createTime},#{updateTime})")
void add(Category category);
}
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();
}
}
}