首页 文章 精选 留言 我的

精选列表

搜索[Java实现],共10000篇文章
优秀的个人博客,低调大师

ASP.NET CORE 1.0 MVC API 文档用 SWASHBUCKLE SWAGGER实现

This article shows how to document your ASP.NET Core 1.0 MVC API using Swagger with Swashbuckle. Per default, it does not use your xml comments in the code and this needs to be configured if required. Code: https://github.com/damienbod/AspNet5GeoElasticsearch 2016.07.03 Updated to ASP.NET Core RTM2016.06.04 Updated to ASP.NET Core RC2 dotnet Step 1: Add the required NuGet packages to the dependencies in the project.json file. 1 2 3 4 5 6 "dependencies" : { "Swashbuckle.SwaggerGen" : "6.0.0-beta901" , "Swashbuckle.SwaggerUi" : "6.0.0-beta901" }, Step 2: Produce the .xml file which contains the xml comments when building. Click the produce outputs on build checkbox in your project file. Or set the ProduceOutputsOnBuild property in the project xproj file. 1 <ProduceOutputsOnBuild>True</ProduceOutputsOnBuild> Step 3: Configure Swashbuckle.SwaggerGen in the Startup class ConfigureServices method. You need to define your path to the comments xml file, which can be found in the artifacts folder. This should be saved in a config file. The ConfigureSwaggerDocument with OperationFilter method is required so that the xml comments are added to the documentation, and also ConfigureSwaggerSchema with ModelFilter 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 public void ConfigureServices(IServiceCollection services) { var pathToDoc = Configuration[ "Swagger:Path" ]; services.AddMvc(); services.AddSwaggerGen(); services.ConfigureSwaggerGen(options => { options.SingleApiVersion( new Info { Version = "v1" , Title = "Geo Search API" , Description = "A simple api to search using geo location in Elasticsearch" , TermsOfService = "None" }); options.IncludeXmlComments(pathToDoc); options.DescribeAllEnumsAsStrings(); }); services.AddScoped<ISearchProvider, SearchProvider>(); } Step 4: Use swagger in the Startup class Configure method. UseSwaggerGen and UseSwaggerUi 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection( "Logging" )); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler( "/Home/Error" ); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default" , template: "{controller=Home}/{action=Index}/{id?}" ); }); app.UseSwagger(); app.UseSwaggerUi(); } Step 5: Create a Controller API with your documentation: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 using Microsoft.AspNet.Mvc; using AspNet5GeoElasticsearch.ElasticsearchApi; using AspNet5GeoElasticsearch.Models; using Newtonsoft.Json; using Swashbuckle.SwaggerGen.Annotations; namespace AspNet5GeoElasticsearch.Controllers { /// <summary> /// This class is used as an api for the search requests. /// </summary> [Route( "api/[controller]" )] [Produces( "application/json" )] public class SearchController : Controller { private readonly ISearchProvider _searchProvider; public SearchController(ISearchProvider searchProvider) { _searchProvider = searchProvider; } /// <summary> /// This method returns the found documents from Elasticsearch /// </summary> /// <param name="maxDistanceInMeter">Distance in meters from your location</param> /// <param name="centerLongitude">center Longitude </param> /// <param name="centerLatitude">center Latitude </param> /// <returns>All the documents which were found</returns> [HttpGet] [Produces( typeof (MapModel))] [SwaggerResponse(System.Net.HttpStatusCode.OK, Type = typeof (MapModel))] [Route( "GeoSearch" )] public ActionResult Search( uint maxDistanceInMeter, double centerLongitude, double centerLatitude) { var searchResult = _searchProvider.SearchForClosest(maxDistanceInMeter, centerLongitude, centerLatitude); var mapModel = new MapModel { MapData = JsonConvert.SerializeObject(searchResult), CenterLongitude = centerLongitude, CenterLatitude = centerLatitude, MaxDistanceInMeter = maxDistanceInMeter }; return Ok(mapModel); } /// <summary> /// Inits the Elasticsearch documents /// </summary> [HttpPost] [Route( "InitData" )] public ActionResult InitData() { initSearchEngine(); return Ok(); } private void initSearchEngine() { if (!_searchProvider.MapDetailsIndexExists()) { _searchProvider.InitMapDetailMapping(); _searchProvider.AddMapDetailData(); } } } } This can then be viewed using ./swagger/ui http://localhost:21453/swagger/ui/index.html Links: https://github.com/domaindrivendev/Swashbuckle https://github.com/domaindrivendev/Ahoy http://blog.sluijsveld.com/28/01/2016/CustomSwaggerUIField/ 修改文档名称及路径: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Swashbuckle.Swagger.Model; using Swashbuckle.SwaggerGen.Application; namespace CoreApi { /// <summary> /// /// </summary> public class Startup { /// <summary> /// 必须,不允许为空字符串 /// </summary> string version = " v1 "; /// <summary> /// API文档路径 /// </summary> string pathToDoc = Path.Combine(AppContext.BaseDirectory, " CoreApi.xml "); /// <summary> /// API项目名称 /// </summary> string appName = " CoreApi "; /// <summary> /// /// </summary> /// <param name="env"></param> public Startup(IHostingEnvironment env) { appName = env.ApplicationName; pathToDoc = Path.Combine(AppContext.BaseDirectory, string.Format( " {0}.xml ", env.ApplicationName)); var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile( " appsettings.json ", optional: true, reloadOnChange: true) .AddJsonFile($ " appsettings.{env.EnvironmentName}.json ", optional: true) .AddEnvironmentVariables(); Configuration = builder.Build(); } /// <summary> /// /// </summary> public IConfigurationRoot Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. /// <summary> /// /// </summary> /// <param name="services"></param> public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(); services.AddSwaggerGen(); services.ConfigureSwaggerGen(options => { options.SingleApiVersion( new Info { Version = version, Title = appName, Description = appName, TermsOfService = " None ", }); options.IncludeXmlComments(pathToDoc); options.DescribeAllEnumsAsStrings(); }); // services.AddScoped<ISearchProvider, SearchProvider>(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. /// <summary> /// /// </summary> /// <param name="app"></param> /// <param name="env"></param> /// <param name="loggerFactory"></param> public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection( " Logging ")); loggerFactory.AddDebug(); app.UseSwagger( " help/{apiVersion}/api.json "); app.UseSwaggerUi( " help ", string.Format( " /help/{0}/api.json ", version)); app.UseMvc(); } } } 本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/p/5694881.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

用tarball实现liferay自动安装部署5-shell 脚本概述

做了前面所有步骤的概述,现在就开始讲解tarball中最核心,也是最重要的部分了--shell script,否则怎么能成为tarball呢。 从总体上,基于公司的需求,我们将脚本分化在5个子脚本中,以下是这些脚本的介绍,我直接从架构文档上复制过来了: Script Name Description configure-helper.sh This script is used for setting the constants,variables and do fundamental calculation or string parsing. configure.sh It will read the constants,variables defined in configure-helper.sh and actually do the fresh install work on a new machine. start.sh It will read configure-helper.sh and start the liferay server. stop.sh It will read configure-helper.sh and stop the liferay server. unconfigure.sh Environment cleanup (Now we haven’t defined the responsibility clearly ,so we leave it blank) 本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/979803,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android实现仿IOS带清空功能的文本输入框

/** *@类名:ClearableEditText *@功能描述: *@作者:WilliamXu *@创建日期:2013-4-13 *@修改人: *@修改日期: *@修改备注: *@版本号:1.0 */ publicclassClearableEditTextextendsEditTextimplements OnFocusChangeListener,TextWatcher{ privateDrawablexD; publicClearableEditText(Contextcontext){ super(context); init(); } publicClearableEditText(Contextcontext,AttributeSetattrs){ super(context,attrs); init(); } publicClearableEditText(Contextcontext,AttributeSetattrs,intdefStyle){ super(context,attrs,defStyle); init(); } privatevoidinit(){ xD=getCompoundDrawables()[2]; if(xD==null){ xD=getResources() .getDrawable(R.drawable.search_clear); } xD.setBounds(0,0,xD.getIntrinsicWidth(),xD.getIntrinsicHeight()); setClearIconVisible(false); super.setOnFocusChangeListener(this); addTextChangedListener(this); } @Override publicvoidsetOnFocusChangeListener(OnFocusChangeListenerf){ this.f=f; } privateOnFocusChangeListenerf; @Override publicbooleanonTouchEvent(MotionEventevent){ if(getCompoundDrawables()[2]!=null){ if(event.getAction()==MotionEvent.ACTION_UP){ booleantappedX=event.getX()>(getWidth() -getPaddingRight()-xD.getIntrinsicWidth()); if(tappedX){ setText(""); event.setAction(MotionEvent.ACTION_CANCEL); } } } returnsuper.onTouchEvent(event); } @Override publicvoidonFocusChange(Viewv,booleanhasFocus){ if(hasFocus){ setClearIconVisible(getText().length()>0); }else{ setClearIconVisible(false); } if(f!=null){ f.onFocusChange(v,hasFocus); } } protectedvoidsetClearIconVisible(booleanvisible){ Drawablex=visible?xD:null; setCompoundDrawables(getCompoundDrawables()[0], getCompoundDrawables()[1],x,getCompoundDrawables()[3]); } @Override publicvoidonTextChanged(CharSequences,intstart,intcount, intafter){ setClearIconVisible(s.length()>0); } @Override publicvoidbeforeTextChanged(CharSequences,intstart,intcount, intafter){ //TODOAuto-generatedmethodstub } @Override publicvoidafterTextChanged(Editables){ //TODOAuto-generatedmethodstub } } 本文转自william_xu 51CTO博客,原文链接:http://blog.51cto.com/williamx/1195051,如需转载请自行联系原作者

资源下载

更多资源
Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码