二十九、spring-boot集成MyBatis使用注解配置增删改查

      spring-boot集成MyBatis使用注解配置增删改查

Spring Boot集成Mybatis后,只需要一个Mapper类,不需要配置文件。

package com.yang.repo;

import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


import com.yang.domain.Enterprise2;

@Mapper
public interface Enterprise2Mapper {

    @Select("select * from enterprise where id=#{id}")  
    public Enterprise2 findByID(@Param("id") Integer id);

    @Select("insert into enterprise(name,address) values(#{name},#{address})")  
    public void insert(@Param("name") String name,@Param("address") String address);

    //以map形式接受参数
    @Insert("INSERT INTO enterprise(name, address) VALUES(#{name,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR})")
    int insertByMap(Map<String, Object> map);


    //以实体类形式接受参数
    @Insert("INSERT INTO enterprise(NAME, address) VALUES(#{name}, #{address})")
    int insertByEnterprise2(Enterprise2 enterprise2);


    //更新
    @Update("update enterprise set name='胖兔子' where id=#{id}")
    void update(@Param("id") Integer id); 


    //删除
    @Delete("DELETE FROM enterprise WHERE id =#{id}")
    void delete(Integer id);



}

猜你喜欢

转载自blog.csdn.net/newbie_907486852/article/details/81415730