//注意: Mapper也是引用tk.mybatis.mapper.common.Mapper包中的
@Repository
public interface UserInfoMapper extends Mapper<UserInfo> {
}
第三步、配置springboot启动类文件
import tk.mybatis.spring.annotation.MapperScan;
@SpringBootApplication
@MapperScan(basePackages = "com.code.mapperdemo.mapper")
public class MapperDemoApplication {
public static void main(String[] args) {
SpringApplication.run(MapperDemoApplication.class, args);
}
}
//注意,MapperScan是引用tk.mybatis.spring.annotation.MapperScan包中的
第四步、配置service实现类文件
@Service
public class UserInfoServiceImpl implements UserInfoService {
@Autowired
private UserInfoMapper userInfoMapper;
@Override
public List<UserInfo> findAll() {
return userInfoMapper.selectAll();
}
}
第五、配置controller文件
@RestController
@RequestMapping("/index")
public class IndexController {
@Autowired
private UserInfoService userInfoService;
@RequestMapping("/findAll")
public List<UserInfo> findAll(){
List<UserInfo> all = userInfoService.findAll();
for (UserInfo userInfo: all
) {
System.out.println("userInfo:"+userInfo.toString());
}
return all;
}
}