Mybatis annotation

The combination of @Select annotation and @Results annotation

The resultMap element in XML has An annotation corresponding to Java @Results, use this annotation to implement attribute mapping.

The following case uses the case

StudentMapper.java in span>2Interface

< /h4>

1, change the select node in the StudentMapper.xml file And comment out resultMap

2, Add @Select annotation and @Results Annotation

Share a picture

3. When using @Results annotations, you may be worried about whether to write this way in every method.

No need at all. We can set the id attribute of the @Results annotation. In other methods, @ResultMap annotation can be used to introduce it.

4. Note: We use annotations to put the original in StudentMapper.xml The SQL words in the file are transferred to the StudentMapper.java interface,

Then, we are configuring The point of the node in the .xml file needs to point to the StudentMapper.java interface.

(4)@Insert@Delete,@Update The use of annotations

The following codes are all completed on the basis of case 1.

1. Comment out the insert, delete, and update nodes in UserMapper.xml

2. Point the mapper node in the configuration.xml file to the UserMapper.java interface

< /p>

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5994 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.