# NanoHttpd_MVC **Repository Path**: y_ut/NanoHttpd_MVC ## Basic Information - **Project Name**: NanoHttpd_MVC - **Description**: No description available - **Primary Language**: Android - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2019-05-22 - **Last Updated**: 2021-08-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Android内嵌nanohttpd服务,简化开发,增加注解功能类似Spring Mvc那样 # 启动服务 ``` package indi.youxiaozhong.http.test; import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.util.Log; import indi.youxiaozhong.http.NanoHttpServer; public class NanoHttpService extends Service { private final String logTag="NanoHttpService"; private NanoHttpServer httpServer; public NanoHttpService() { } @Override public int onStartCommand(Intent intent, int flags, int startId) { if(this.httpServer == null) { this.httpServer = new NanoHttpServer(this, 8080,false); //this.httpServer.addInterceptor(new SecurityCheckinterceptor()); try { this.httpServer.start(6000, true); Log.i(logTag, "HTTP服务已启动"); } catch (Exception e) { e.printStackTrace(); Log.e(logTag, "启动HTTP服务异常", e); } } return super.onStartCommand(intent, flags, startId); } @Override public IBinder onBind(Intent intent) { // TODO: Return the communication channel to the service. throw new UnsupportedOperationException("Not yet implemented"); } } ``` # Web控制器(静态页面放在assets/www目录下) ``` package indi.youxiaozhong.http.test; import indi.youxiaozhong.http.annotation.RequestMapping; import indi.youxiaozhong.http.annotation.ResponseBody; @RequestMapping("/test") public class HttpMvcTest { @RequestMapping("") @ResponseBody public String test(){ return "\r\n