SpringBoot整合MyBatis完成用戶查詢


接上面工程代碼,可以參考:https://www.cnblogs.com/braveym/p/11349409.html

 

1 、mapper 接口中以及映射配置文件中添加相關代碼

修改UserMapper接口

 

 

 

修改UsersMapper.xml文件

 

 

 2 、在業務層中添加查詢方法

 在UserService接口中添加一下內容

 

 

 在UserServiceImpl類里面添加以下方法

 

 

 3 Controller 中添加方法

    /**
     * 查詢全部用戶
     */
    @RequestMapping("/findUserAll")
    public String findUserAll(Model model){
        List<Users> list = this.usersService.findUserAll();
        model.addAttribute("list", list);
        return "showUsers";
    }

 

 

 

新建showUsers.html

<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>展示用戶數據</title>
</head>
<body>
    <table border="1" style="width:300px;">
        <tr>
            <th>用戶ID</th>
            <th>用戶姓名</th>
            <th>用戶年齡</th>
        </tr>
        <tr th:each="user : ${list}">
            <td th:text="${user.id}"></td>
            <td th:text="${user.name}"></td>
            <td th:text="${user.age}"></td>
        </tr>
    </table>
</body>
</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM