Spring Boot Learning six spring inheriting MyBatis (based on annotations)

Source: Internet
Author: User

MyBatis provides several annotations such as: @InsertProvider, @UpdateProvider, @DeleteProvider and @selectprovider, These are the ways to build dynamic languages and let MyBatis perform these languages using annotation-based mybatis, or better.

First is to define Mapper, @ Selectprovider to declare class (Citysqlprovide) and method name (findbystate),

 Public Interface Citymapper {    = citysqlprovide.  Class"findbystate")    List<City> findbystate (@Param ("  State"), String State);

Second, it is difficult and error-prone to construct query statements with string. So MyBatis provides a method of constructing SQL common methods without having to write out a complete string statement . Let's look at the common methods of how to use Org.apache.ibatis.jdbc.SQL.

import Org.apache.ibatis.jdbc.SQL;  Public class citysqlprovide {    public  string findbystate (string state) {        return  New  SQL () {            this. Select ("*"). From ("City"). WHERE ("state= #{state}");}        . ToString ();    }}

Spring Boot Learning six spring inherits MyBatis (note-based)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.