首页 \ 问答 \ swagger 怎么整合springmvc 文档

swagger 怎么整合springmvc 文档

更新时间:2022-04-22 15:04

最满意答案

abstract class Person {
 public abstract void Eat();
 public abstract void Sellp();
}

interface Father {
 public void Smoking();
 public void GoFishing();
}

interface Mon {
 public void WatchTV();
 public void Cook();
}

class Me extends Person implements Father,Mon{         //使用“implements”来实现接口
 public void Eat() {
  System.out.println("我喜欢吃鱼香茄子");
}

 public void Sellp() {
  System.out.println("我喜欢睡觉时做梦");
}

 public void Smoking() {
  System.out.println("我不喜欢抽烟");
}

 public void GoFishing() {
  System.out.println("我喜欢钓鱼");
}

 public void WatchTV() {
  System.out.println("我喜欢看电视");
}

 public void Cook() {
   System.out.println("我不太会做菜");
 }
}

public class Test {
 public static void main(String[] args) {
  Person p1 = new Me();                      
  p1.Eat();
  p1.Sellp();

  Mon m1 = (Mon)p1;
  m1.WatchTV();
  m1.Cook();
 }
}

其他回答

举个例子

首先我有一个接口叫做saveuserservice,里面有个方法较public void save()然后我又写了一个jdbcsaveuserimpl实现上述接口,这样我必然要重写这个save方法,由于方法名我定义了脚jdbc我必然要在代码里面写上各种连接语句(没有那么变态的写了jdbc不用jdbc编程的)

而我在客户端一侧的所谓试图层如果要保存用户信息自然要调用save方法,这个时候我要先声明一个saveuserservice接口的引用然后给他赋值成jdbcsaveuserimpl的实例,也就是new jdbcsaveuserimpl();(当然正式项目不会这么new,一定会用各种模式比如工厂模式,或者spring的ioc把这个实力注入进来)

调用的时候自然用的是jdbcsaveuserimpl里面的save方法,但是现在需求变了,要用hibernate来连数据库,怎么办?自然是写一个hibernatesaveuserimpl里同样实现上述的接口,这时候save方法里面就写hibernate的内容了,然后在修改spring的配置文件让ioc注入新的实现类实例

哇,前台的各层里面内容一点都不用改,这不就是传说中的高内聚,松耦合,提高代码的重用性么?如此happy并且偷懒的方法自然要广泛弘扬了

这里只举了一个类的例子,设想下如果是300个功能的大系统,如果你的领导万一哪天抽风要换实现方式,难道你每个类都改?300个功能可能会调用上千次实例,每个都改必然是死定了,天天加班到12点,但是如果用了spring加接口加多层架构,你只需要改中间某些层然后修改下spring的配置文件就ok了

如果都这么说了还没明白就继续学,学到完整做个工程时候就明白了
这是一个接口A
public interface A{
    void run();
}
这是一个接口B
public interface B{
   void eat();
}
这个类C去实现了A的同时又实现了B。。那么它的同时去实现A和B里面的方法
public class C implement A,B{
  public void run(){ System.out.println("我会跑");}
  public void eat(){System.out.println("我会吃");}
}
简单吧。。。

相关问答

更多
  • 1. java提供webservice接口 2. java提供普通的访问接口(其他程序调用) 1. 比如天气预报写个接口 public String getWeather(int type){ //type表示城市ID,这样 return "天气信息"; } 2. 别人就可以访问getWeather这个接口获取天气信息
  • //定义接口IFruit public interface IFruit{ public String name="fruit"; public String getName(); //接口中的抽象方法 } //定义Farmer类用创建不同的实例对象 public class Farmer{ public void plant(IFruit fruit){ System.out.println("种植了:"+fruit.getName()); } } //Apple是实现IFruit接口 public cl ...
  • java 接口[2022-10-23]

    java接口是这样定义的,,接口是一个特殊的抽象类,定义一系列的方法但是没有方法的实现,,方法的实现放的接口的实现中,,,,请问:为什么要这样啊, 要什么好处啊,,(有例子最好)你问的为什么要这样我不知道具体问的是什么 ,请下次点明问题,也好让大家来回答,下面就我的理解来说下。1.为什么接口的方法要放在实现类中实现:答:首先你得明白接口的作用和好处(另外提一点,接口的出现是为了让java实现多继承,其本质上的作用和继承差不多),假设有一个接口A是甲定义的,乙、丙、丁为了减少代码的重用,分别去实现接口A,而甲 ...
  • 接口 / Interface 的存在非但不是“多此一举”,而是让开发者能够“相对”更加灵活地定义不同的类。 接口当中只是单纯地给出方法名字也正是为了能够让开发人员能够根据具体地需求去 实现 / implement 接口当中的各个方法。 举个例子。 我定义了一个接口 叫做 Eat / 吃 我又定义了几个类,人,鳄鱼,昆虫。他们都可以归为一个父类“生物” 但应用到实际中,人可以实现吃的功能,鳄鱼可以吃,昆虫也可以吃。但是相对于彼此之间“吃”必然会存在差异。那么“接口”这个概念就可以从某一个方面满足我们对于以上3 ...
  • abstract class Person { public abstract void Eat(); public abstract void Sellp(); } interface Father { public void Smoking(); public void GoFishing(); } interface Mon { public void WatchTV(); public void Cook(); } class Me extends Person implements Father, ...
  • JAVA继承和接口[2022-06-12]

    举个例子 首先我有一个接口叫做SaveUserService,里面有个方法较public void save()然后我又写了一个JDBCSaveUserImpl实现上述接口,这样我必然要重写这个save方法,由于方法名我定义了脚JDBC我必然要在代码里面写上各种连接语句(没有那么变态的写了jdbc不用jdbc编程的) 而我在客户端一侧的所谓试图层如果要保存用户信息自然要调用save方法,这个时候我要先声明一个SaveUserService接口的引用然后给他赋值成JDBCSaveUserImpl的实例,也就是 ...
  • 请教com接口问题[2022-03-08]

    LocalSecurityAuthority.Debug 提升权限到Debug直接阻止,非常重要,除非是完全信任的程序LocalSecurityAuthority.SystemTime 修改系统时间直接阻止。 通常只允许rundll32 修改系统时间。LocalSecurityAuthority.Restore 系统还原,可以绕过已设置的文件、注册表权限,非系统程序直接阻止
  • 这不是一个很好的问题。 任何对象都可以是唯一的一个类(忽略像int这样的非对象原语)。另一方面,类可以有任意数量的超类,所以你的类可以匹配一个artitrary的“is a”关系其他类的数量。 在接口问题中,所有接口引入的都是“合同” - 您正在承诺实现某些方法或具有某些属性。 这有点类似于多重继承,但不是真正的多重继承。 同样,实现一个接口意味着类有另一个“是”属性,但这并不意味着它完全引入了其他类。 It's not a very well-posed question. Any object can ...
  • 没有必要在超类中实现这些功能 假设如果 interface X(){ function A(); function B(); } class A implements X(){ @override function A(){ //do something } function B(){ //do something } } class B extends A{ } class C extends A{ } //-> that time your subclass need to i ...
  • 否。接口定义了实现应该如何与外部世界通信,而不是定义任何行为。 您当然可以实现多个接口,但这并不意味着您有多个继承,只是实现接口的类可以显示为不同的东西。 No. An interface defines how an implementation should communicate with the outside world you do not define any behavior. You can of course implement multiple interfaces but that ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)