1、創建一個person.thrift文件,添加如下內容:
namespace java cn.horace.thrift.idl // 定義命名空間 // include "test.thrift" // 包含外部的接口文件 /* 定義一個Person類 */ struct User { 1: i32 id, // Id 2: string username, // 名稱 3: optional string nickname, // 昵稱 4: optional i32 gender, // 性別,1:男,2:女,3:其他 5: optional string email, // 郵箱 } /* 服務接口 */ service IUserService { /* 添加一個用戶 */ void add(1:User user), /* 根據Id刪除一個用戶 */ void deleteById(1:i32 id), /* 根據Id更新一個用戶 */ void updateById(1:User user), /* 根據Id查詢一個用戶 */ User findById(1:i32 id), /* 查詢全部用戶 */ list<User> findAll(), }
2、下載Thrift的編譯文件,注意需要對應好jar包版本:http://www.apache.org/dyn/closer.cgi?path=/thrift/0.9.2/thrift-0.9.2.exe
3、生成Java文件
thrift-0.9.2.exe -gen java person.thrift