/mybatis-in-action

Java basic practice for beginners: mybatis

Primary LanguageJava

MyBatis实战

我在UserDaoOrderDao里给你准备了很多和SELECT相关的题目,请完成之。

要完成这个挑战,你需要:

  • 通过mvn initialize将数据库初始化(灌入数据),方便你进行各种SQL语句的测试。
  • 自己从零开始配置MyBatis。这会让你熟悉JDBC、ORM以及MyBatis的各种概念。
  • 完成各种复杂的SQL查询方法。我们鼓励你尝试不同的XML或者注解方式。

用户名是root,密码是Jxi1Oxc92qSj

数据库中的初始数据如下所示:

用户表:
+----+----------+------+----------+
| ID | NAME     | TEL  | ADDRESS  |
+----+----------+------+----------+
| 1  | zhangsan | tel1 | beijing  |
+----+----------+------+----------+
| 2  | lisi     | tel2 | shanghai |
+----+----------+------+----------+
| 3  | wangwu   | tel3 | shanghai |
+----+----------+------+----------+
| 4  | zhangsan | tel4 | shenzhen |
+----+----------+------+----------+
商品表:
+----+--------+-------+
| ID | NAME   | PRICE |
+----+--------+-------+
| 1  | goods1 | 10    |
+----+--------+-------+
| 2  | goods2 | 20    |
+----+--------+-------+
| 3  | goods3 | 30    |
+----+--------+-------+
| 4  | goods4 | 40    |
+----+--------+-------+
| 5  | goods5 | 50    |
+----+--------+-------+
订单表:
+------------+-----------------+------------------+---------------------+-------------------------------+
| ID(订单ID) | USER_ID(用户ID) | GOODS_ID(商品ID) | GOODS_NUM(商品数量) | GOODS_PRICE(下单时的商品单价)        |
+------------+-----------------+------------------+---------------------+-------------------------------+
| 1          | 1               | 1                | 5                   | 10                            |
+------------+-----------------+------------------+---------------------+-------------------------------+
| 2          | 2               | 1                | 1                   | 10                            |
+------------+-----------------+------------------+---------------------+-------------------------------+
| 3          | 2               | 1                | 2                   | 10                            |
+------------+-----------------+------------------+---------------------+-------------------------------+
| 4          | 4               | 2                | 4                   | 20                            |
+------------+-----------------+------------------+---------------------+-------------------------------+
| 5          | 4               | 2                | 100                 | 20                            |
+------------+-----------------+------------------+---------------------+-------------------------------+
| 6          | 4               | 3                | 1                   | 20                            |
+------------+-----------------+------------------+---------------------+-------------------------------+
| 7          | 5               | 4                | 1                   | 20                            |
+------------+-----------------+------------------+---------------------+-------------------------------+
| 8          | 5               | 6                | 1                   | 60                            |
+------------+-----------------+------------------+---------------------+-------------------------------+

在提交Pull Request之前,你应当在本地确保所有代码已经编译通过,并且通过了测试(mvn clean verify)


注意!我们只允许你修改以下文件,对其他文件的修改会被拒绝:


完成题目有困难?不妨来看看写代码啦的相应课程吧!

回到写代码啦的题目,继续挑战!