Spring Boot MyBatis 使用注解動態表名查詢


代碼如下:

package com.peraglobal.mapper;

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;

@Mapper
public interface UcenterUserMapper {

  @Select("select * from ${tableName}")
     public List<User> selectAll(@Param(value = "tableName") String tableName);

}

service 層調用,如下:

package com.peraglobal.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import com.peraglobal.mapper.UserMapper;
import com.peraglobal.model.User;

 

@Service
public class UcenterUserService {

  @Autowired
       private UserMapper userMapper;

  public List<User> selectAll() {
           return ucenterUserMapper.selectAll("user");
     }

}

user 是需要傳遞的動態表名


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM