Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
There was an unexpected error (type=Internal Server Error, status=500).
File UserController:
Assistant
Unexpected end of JSON input
User
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
There was an unexpected error (type=Internal Server Error, status=500).
File UserController:
import net.crud.springbootcrud.model.User;
import net.crud.springbootcrud.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import java.util.List;
@Controller
public class UserController {
private final UserService userService;
@Service
public class UserService {
private final UserRepository userRepository;
code
public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
}
public User findById(Long id){
Optional<User> userOptional = userRepository.findById(id);
if(userOptional.isPresent()){
return userOptional.get();
}
throw new IllegalArgumentException("User with id " + id + " doesn't exist");
}
public List<User> findAll(){
return userRepository.findAll();
}
public User saveUser(User user){
if(user.getUsername() == null || user.getUsername().isEmpty()){
throw new IllegalArgumentException("Username can not be empty");
}
return userRepository.save(user);
}
public void deleteById(Long id){
Optional<User> userOptional = userRepository.findById(id);
if(userOptional.isPresent()){
userRepository.deleteById(id);
}
else{
throw new IllegalArgumentException("User with id " + id + " doesn't exist");
}
}
The code seems to be fine and there are no syntax errors in it. However, the error could be due to an issue with the database connection or with the data being passed into the UserController. Please check the database connection and ensure that the necessary tables and columns exist in the database. Also, ensure that the data being passed into the UserController is valid and not causing any issues.
User
In the "error.html" file, add the HTML code for the error page, which can include a message, an image, and a link to return to the home page.
Assistant
User
In this html:
Assistant
User
In this html code:
Assistant
User
Fix this.
Assistant
The issue is with the quotes used in the HTML code, they are smart quotes which are not recognized by HTML. Here's the corrected code: