emptygif
ભાષા: ગુજરાતી

બધી ભાષાઓ અને ફ્રેમવર્ક

Spring Boot Java

Spring Boot માટે Java સ્નિપેટ, જે /pixel.gif પરની રિક્વેસ્ટનો જવાબ empty GIF થી આપે છે. GIF સ્ટાર્ટઅપ વખતે એક જ વાર ડિકોડ થાય છે.

Spring Boot Java

ઇન્સ્ટૉલ
https://start.spring.io/ (dependency: Spring Web)
ફાઇલ
PixelApplication.java
ચલાવો
./gradlew bootRun
package com.example.pixel;

import java.util.Base64;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.CacheControl;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class PixelApplication {

    private static final byte[] GIF = Base64.getDecoder().decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");

    @GetMapping("/pixel.gif")
    ResponseEntity<byte[]> pixel() {
        return ResponseEntity.ok()
                .contentType(MediaType.IMAGE_GIF)
                .cacheControl(CacheControl.noStore())
                .body(GIF);
    }

    public static void main(String[] args) {
        SpringApplication.run(PixelApplication.class, args);
    }
}

અમે આ સ્નિપેટ ચલાવ્યો અને તેણે પરત કરેલા બાઇટની સરખામણી કરી.

ચકાસો

curl -sI http://localhost:8080/pixel.gif

સત્તાવાર સાઇટ: Spring Boot

Java માં વધુ