大佬可以支持下jdk17的jakarta包吗,用的是quarkus
Closed this issue · 0 comments
zundaren commented
package com.example.q.api;
import cn.hutool.core.map.MapUtil;
import com.example.q.R;
import com.example.q.service.UserService;
import jakarta.inject.Inject;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import lombok.Data;
import org.jboss.resteasy.reactive.RestQuery;
import org.jboss.resteasy.reactive.server.multipart.FormValue;
import org.jboss.resteasy.reactive.server.multipart.MultipartFormDataInput;
import java.io.File;
import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Map;
@Path("user")
public class UserApi {
@Inject
UserService userService;
@Path("/get")
@GET
public R<String> get(@RestQuery String name) {
System.out.println("get " + name);
return R.ok(name + userService.plus(1, 2));
}
@Path("/form")
@POST
@Consumes(value = MediaType.APPLICATION_FORM_URLENCODED)
public R<String> form(FormDto dto) {
System.out.println("form " + dto);
return R.ok(dto.name);
}
@Path("/file")
@POST
@Consumes(value = MediaType.MULTIPART_FORM_DATA)
public R<String> file(MultipartFormDataInput dto) {
Map<String, Collection<FormValue>> map = dto.getValues();
if (MapUtil.isEmpty(map)) {
return R.ok("");
}
ArrayDeque<FormValue> name = (ArrayDeque<FormValue>) map.get("name");
System.out.println("name: " + name.peek().getValue());
ArrayDeque<FormValue> file = (ArrayDeque<FormValue>) map.get("file");
file.forEach(f -> {
System.out.println(f.getFileName());
});
return R.ok("yes");
}
@Path("/download")
@GET
@Produces(value = MediaType.APPLICATION_OCTET_STREAM)
public Response download() {
File file = new File("/Users/chenbo36/Downloads/截图/0c643657f9189a6738104e9496daa7db.jpg");
return Response.ok(file, MediaType.APPLICATION_OCTET_STREAM)
.header("content-disposition", "attachment; filename=t.jpg")
.header("Content-Length", file.length())
.build();
}
@Path("/json")
@POST
public R<String> json(JsonDto dto) {
System.out.println("json " + dto.name);
return R.ok(dto.name);
}
public record User(String name) {}
@Data
public static class JsonDto implements Serializable {
@Serial
private static final long serialVersionUID = 5491427643900320990L;
private String name;
}
@Data
public static class FormDto implements Serializable {
@Serial
private static final long serialVersionUID = 5491427643900320990L;
@FormParam(value = "name")
private String name;
}
}