restlet简易使用说明

因为公司的代码库中使用的restlet版本较老,在central和restlet库中都没法找到。
在maven项目中使用时,须要手动添加到本地库中,十分繁琐。所以决定使用新版本替换。java

实验环境:

  • JDK 1.8

添加依赖

<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  <modelVersion>4.0.0</modelVersion>  
  <groupId>qiuqiu</groupId>  
  <artifactId>restlet</artifactId>  
  <version>0.0.1-SNAPSHOT</version>  
 
  <repositories>
      <repository>
          <id>maven-restlet</id>
          <name>Public online Restlet repository</name>
          <url>http://maven.restlet.org</url>
      </repository>
  </repositories>

  <dependencies> 
    <dependency> 
      <groupId>org.restlet.jee</groupId>  
      <artifactId>org.restlet</artifactId>  
      <version>2.3.10</version> 
    </dependency> 
  </dependencies> 
</project>

注意:在 central 库中没法找到,须要添加 restlet 库。apache

代码示例

第一个

直接拿官方的示例~浏览器

package restlet;

import org.restlet.Server;
import org.restlet.data.Protocol;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;

public class FirstServerResource extends ServerResource {

    public static void main(String[] args) throws Exception {
        // Create the HTTP server and listen on port 8182
        new Server(Protocol.HTTP, 8182, FirstServerResource.class).start();
    }

    @Get
    public String toString() {
        return "hello, world";
    }

}

运行后,在浏览器中访问 http://localhost:8182
图片描述maven

访问 http://localhost:8182/aaa/ddd
图片描述ide

可见,这里是设置了一个默认的返回值。ui

第二个

参考:

相关文章
相关标签/搜索