首页  

quarkus qute 例子     所属分类 quarkus 浏览量 757
Qute is a templating engine 
In the development mode, all files located in src/main/resources/templates are watched for changes and modifications are immediately visible
 

https://quarkus.io/guides/qute

qute-quickstart
https://github.com/quarkusio/quarkus-quickstarts/tree/main/qute-quickstart


quarkus-quickstarts
https://github.com/quarkusio/quarkus-quickstarts/archive/main.zip

https://github.com/quarkusio/quarkus-quickstarts/tree/main/getting-started

 
增加 QuteDemoAppMain 
import io.quarkus.runtime.annotations.QuarkusMain;
import io.quarkus.runtime.Quarkus;

@QuarkusMain
public class QuteDemoAppMain {

    public static void main(String ... args) {
        System.out.println("QuteDemoAppMain start");
        Quarkus.run(args);
    }
}

直接 main 方法启动

设置jvm 参数指定端口
-Dquarkus.http.port=8086

配置文件里也可指定 ( jvm 参数 优先级高)
src/main/resources/application.properties
quarkus.http.port=8086

注意需要 jdk11
 Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: io/quarkus/bootstrap/runner/QuarkusEntryPoint has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

可设置 java_home
export JAVA_HOME=/Users/dyyx/soft/jdk/jdk-11.0.13.jdk/Contents/Home

端口冲突 报错
ERROR [io.qua.run.Application] (main) Port 8086 seems to be in use by another process. Quarkus may already be running or the port is used by another application.
WARN  [io.qua.run.Application] (main) Use 'netstat -anv | grep 8086' to identify the process occupying the port.



MyHello.java import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import javax.inject.Inject; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import io.quarkus.qute.Template; import io.quarkus.qute.TemplateInstance; @Path("/myhello") public class MyHello { @Inject Template hello1; @Inject Template hello2; @Inject Template hello3; @GET @Path("/hello1") @Produces(MediaType.TEXT_HTML) public TemplateInstance hello1(@QueryParam("name") String name) { return hello1.data("name", name); } @GET @Path("/hello2") @Produces(MediaType.TEXT_HTML) public TemplateInstance hello2(@QueryParam("name") String name) { return hello2.data("name", name); } @GET @Path("/hello3") @Produces(MediaType.TEXT_HTML) public TemplateInstance hello3(@QueryParam("name") String name) { List items = new ArrayList<>(); items.add(new Item(new BigDecimal(10), "Apple")); items.add(new Item(new BigDecimal(16), "Pear")); items.add(new Item(new BigDecimal(30), "Orange")); ItemsData data = new ItemsData(); data.setItems(items); TemplateInstance templateInstance = hello3.data("name", name); templateInstance.data("data", data); return templateInstance; } }
模板 src/main/resources/templates hello1.html hello2.html hello3.html 模板文件如何 按文件夹存放 ? http://127.0.0.1:8086/hello http://127.0.0.1:8086/myhello/hello1 http://127.0.0.1:8086/myhello/hello2 http://127.0.0.1:8086/myhello/hello3
静态资源放在 /src/main/resources/META-INF/resources http://127.0.0.1:8086/html/hello.html http://127.0.0.1:8086/txt/hello.txt http://127.0.0.1:8086/style/hello.css http://127.0.0.1:8086/js/hello.js
java -jar ./target/quarkus-app/quarkus-run.jar xxx-runner.jar , 依赖 在 lib 目录中 target/quarkus-app java -Dquarkus.http.port=8078 -jar quarkus-run.jar
Run Quarkus as a native executable ./mvnw package -Dnative ./target/getting-started-1.0.0-SNAPSHOT-runner
完整例子代码 https://gitee.com/dyyx/hellocode/tree/master/demo/quarkus/qute-quickstart
quarkus 例子项目

上一篇     下一篇
go import 方式

temporal server 远程调试

go test 实例

Java 异步编程

quarkus hibernate 例子

quarkus 打包类型 quarkus.package.type