浏览器页面显示:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Oct 13 23:52:27 CST 2020
There was an unexpected error (type=Internal Server Error, status=500).
后端报错:
2020-10-13 23:52:27.329 ERROR 19779 — [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
代码分别实:
package com.itmuch.usercenter.service.user;
import com.itmuch.usercenter.dao.user.UserMapper;
import com.itmuch.usercenter.domain.entity.user.User;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class UserService {
@Resource
private UserMapper userMapper;
public User findUserId(Integer id){
return this.userMapper.selectByPrimaryKey(id);
}
}
package com.itmuch.usercenter.controller.user;
import com.itmuch.usercenter.domain.entity.user.User;
import com.itmuch.usercenter.service.user.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/users")
public class UserController {
private UserService userService;
@GetMapping("/{id}")
public User findUserId(@PathVariable Integer id){
return this.userService.findUserId(id);
}
}
面向未来微服务:熟练掌握Spring Cloud Alibaba
了解课程