Introduction
In this project, you will learn how to use MyBatis, a popular Java persistence framework, to interact with a MySQL database. Specifically, you will learn how to use input parameters in SQL queries and retrieve course information based on the teacher's name.
ð Preview
[labex] DEBUG [main] - Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@642a7222]
[labex] DEBUG [main] - ==> Preparing: SELECT * FROM course WHERE teacher LIKE CONCAT('%', ?, '%') ORDER BY cNo DESC
[labex] DEBUG [main] - ==> Parameters: Am(String)
[labex] DEBUG [main] - <== Total: 2
Course Number: 3 Course Name: Python Teacher: Liam
Course Number: 1 Course Name: HTML Teacher: Amy
ðŊ Tasks
In this project, you will learn:
- Implement the
CourseMapper
interface to define a method for retrieving courses based on the teacher's name - Write the SQL query in the
CourseMapper.xml
file to perform a fuzzy search on theteacher
column and sort the results in descending order by course number - Test the
CourseMapper
implementation in theMyBatisTest
class to ensure the desired functionality
ð Achievements
After completing this project, you will be able to:
- Use MyBatis to interact with a MySQL database
- Pass input parameters to SQL queries using a
Map
- Perform a fuzzy search on a database column and sort the results
- Test the functionality of a MyBatis mapper using a JUnit test case