|  | 
 
| 
下面是一段响应数据
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  {
 "code": 0,
 "message": "操作成功",
 "data": [
 {
 "id": 1,
 "categoryName": null,
 "categoryAlias": null,
 "createUser": null,
 "createTime": null,
 "updateTime": null
 },
 {
 "id": 2,
 "categoryName": null,
 "categoryAlias": null,
 "createUser": null,
 "createTime": null,
 "updateTime": null
 }
 ]
 }
 在数据库里 字段值全不为null 但是 响应数据里字段值全为null是哪里出问题了
 
 CategoryController类里代码如下
 package com.example.demo.controller;
 
 import java.util.List;
 
 import org.apache.ibatis.annotations.Mapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
 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;
 
 import com.example.demo.pojo.Category;
 import com.example.demo.pojo.Result;
 import com.example.demo.service.CategoryService;
 
 @Mapper
 @RestController
 @RequestMapping("/category")
 public class CategoryController {
 
 @Autowired
 private CategoryService categoryService;
 
 @PostMapping
 public Result add(@RequestBody @Validated Category category) {
 categoryService.add(category);
 return Result.success();
 }
 
 @GetMapping
 public Result<List<Category>> list(){
 List<Category> cs = categoryService.list();
 return Result.success(cs);
 
 }
 }
 
 CategoryServiceImpl类里代码如下
 
 package com.example.demo.service.impl;
 
 import java.util.List;
 import java.util.Map;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import com.example.demo.mapper.CategoryMapper;
 import com.example.demo.pojo.Category;
 import com.example.demo.service.CategoryService;
 import com.example.demo.util.ThreadLocalUtil;
 
 @Service
 public class CateServiceImpl implements CategoryService{
 
 @Autowired
 private CategoryMapper categoryMapper;
 
 @Override
 public void add(Category category) {
 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);
 
 }
 
 }
 
 CategoryMapper类里代码如下
 
 package com.example.demo.mapper;
 
 import java.util.List;
 
 import org.apache.ibatis.annotations.Insert;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Select;
 
 import com.example.demo.pojo.Category;
 
 @Mapper
 public interface CategoryMapper {
 
 @Insert("insert into category (category_name,category_alias,create_user,create_time,update_time)"+
 "value(#{categoryName},#{categoryAlias},#{createUser},now(),now())")
 void add(Category category);
 
 @Select("select * from category where create_user=#{userId}")
 List<Category> list(Integer userId);
 
 }
 
 
 请问出现响应数据里字段值全为null的原因是什么
 
出现响应数据里字段值全为null的原因可能是以下几个方面:
 1. 数据库中的数据没有正确插入:检查一下数据库插入操作是否正常,可以在add方法中打印一些日志或者调试信息,确认数据是否正确插入到数据库中。
 
 2. 数据库查询操作有误:检查list方法中查询操作是否正确,可以在list方法中打印一些日志或者调试信息,确认查询语句是否正确执行,并返回了期望的结果。
 
 3. 数据库连接配置有误:如果数据库连接配置有问题,例如连接URL、用户名、密码等不正确,可能导致无法正确地读写数据库中的数据。
 
 综合以上几点,可以逐步排查问题所在。如果可以提供更多的错误日志或相关代码,我可以给出更具体的解答。
 
 以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
 | 
 |