Java Learning---Common Bug Collection in SpringBoot [Continuous Update]

1. The running problem of the cloned project

1.1.maven dependency plug-in problem

Insert picture description here


1.2. Prompt Cannot start complier

![Insert picture description here](https://img-blog.csdnimg.cn/20210116231831836.png

Reason: missing out directory




2. Spring Boot project startup and operation problems

2. Code compilation error (compiling during dependency injection)Insert picture description here


2.2. Startup class not foundInsert picture description here


2.3. Multiple startup problemsInsert picture description here


2.4. Null pointer exception at runtimeInsert picture description here


2.5. Cannot find the corresponding Bean objectInsert picture description here


2.6. Dependency injection exceptionInsert picture description here


2.7. Unit test test method definitionInsert picture description here


2.8. The definition of non-unique Bean is abnormalInsert picture description here




3. Database connection problem in SpringBoot project

3.1. URL is not configured or configured incorrectlyInsert picture description here


3.2. Communication abnormal when establishing url connectionInsert picture description here


3.3. Rejected when accessing the database

Insert picture description here




4. MyBatis integration problem in SpringBoot project

4.1. SQL mapping not foundInsert picture description here


4.2. The attribute described by Autowired has an error message

Insert picture description here


4.3. BindingException BindingException

Insert picture description here




5. Web request problem in SpringBoot project

5.1. The service is not started successfully or the access port is wrongInsert picture description here


5.2. Analysis of the problem of port occupied when the service starts

Insert picture description here


5.3. Request 404 problem and solution analysis

Insert picture description here


5.4. Thymeleaf template does not exist exception

Insert picture description here


5.5. JSON data conversion abnormal analysis

Insert picture description here


5.6. 400 request exception analysisInsert picture description here


5.7. 405 Request exception analysisInsert picture description here


6. Exceptions in Ajax

6.1 Concurrent update exception

Insert picture description here

6.2 No response after the event is triggered

Insert picture description here

6.3 Object property access problemInsert picture description here

6.4 Cross-domain access issuesInsert picture description here

6.5 Access function does not existInsert picture description here

6.6 Callback function understanding problemInsert picture description here

6.7 Request 415 exception problemInsert picture description here

6.8 There is no problem with small iconsInsert picture description here

7. Bug in JS/JQuery/Ajax

7.1 Cannot receive ajax return value

Insert picture description here

    //页面加载完成异步加载当前页数据
    function doGetObjects() {
    
    
        var id = getCurrentUserData();
        console.log("当前用户id=" + id);
        let url = `user/doFindUserInfo/${
      
      id}`;
        $.ajax({
    
    
            url,
            success(result) {
    
    
                doHandleResponseResult(result);
            }
        });
    }

    function getCurrentUserData() {
    
    
        var id ;
        $.ajax({
    
    
            url: "user/doFindCurrentUserId",
            async: false,
            success: function (result) {
    
    
                id = result;
            }
        })
        return id;
    }

8. Problems in shiro

8.1 SecurityUtils.getSubject().getPrincipal()为null

Solution: Only the SecurityUtils.getSubject().getPrincipal() obtained under the User class and UserController/UserService is the user object. In other methods, the value is not available (null value), so a new one in SysUserServiceImpl HashMap encapsulates and returns object information, and then call this method from other locations!

 @Override
    public HashMap<String, Object> getCurrentUserData() {
    
    
        SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal();
        HashMap<String, Object> map = new HashMap<>();
        map.put("id", user.getId());
        map.put("username", user.getUsername());
        map.put("password", user.getPassword());
        map.put("salt", user.getSalt());
        map.put("sex", user.getSex());
        map.put("email", user.getEmail());
        map.put("mobile", user.getMobile());
        map.put("valid", user.getValid());
        map.put("createdTime", user.getCreatedTime());
        map.put("modifieTime", user.getModifiedTime());
        map.put("createdUser", user.getCreatedUser());
        map.put("birthday", user.getBirthday());
        return map;
    }

Then the other Service layer can call this method to realize the business

@Override
    public int reserveSeat(SysSeat entity) {
    
    
        HashMap<String, Object> userMap = sysUserService.getCurrentUserData();
        entity.setUsedUser((String) userMap.get("username"));
        entity.setState(2);
        return sysSeatDao.reserveSeat(entity);
    }

Insert picture description here
Appearance time: 2021/2/9 11:50 After the seat is successfully reserved in the library seat management system, the user name of the reserved user is displayed as the list

Guess you like

Origin blog.csdn.net/weixin_40597409/article/details/112726800