美文网首页
接口编写

接口编写

作者: simplehych | 来源:发表于2019-02-01 15:15 被阅读0次

最简单的编写

屏幕快照 2019-02-01 下午2.34.44.png 屏幕快照 2019-02-01 下午2.35.26.png 屏幕快照 2019-02-01 下午2.36.09.png 屏幕快照 2019-02-01 下午2.37.37.png 屏幕快照 2019-02-01 下午2.38.01.png 屏幕快照 2019-02-01 下午2.57.59.png

新建 DemoRestController

@RestController
public class DemoRestController {

    @RequestMapping("/hello") 
    public String hello() {
        return "Hello World!";
    }
}

pom.xml 添加依赖

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
 </dependency>
屏幕快照 2019-02-01 下午3.07.57.png

点击右上角运行

验证
在浏览器或者 postman 输入 http://localhost:8080/hello,输出"Hello World!"

数据操作层框架 Mybatis

http://www.spring4all.com/article/145

自动生成Mybatis 各种采坑

Q:
Description:
Field cityMapper in com.simple.helloworld.service.impl.CityServiceImpl required a bean of type 'com.simple.helloworld.mapper.CityMapper' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.simple.helloworld.mapper.CityMapper' in your configuration.

A:
添加包路径 @MapperScan("com.simple.helloworld.mapper")``, scanBasePackages={"com.simple.helloworld.mapper"}

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class ,scanBasePackages={"com.simple.helloworld.mapper"})
@MapperScan("com.simple.helloworld.mapper")
public class HelloworldApplication {
    public static void main(String[] args) {
        SpringApplication.run(HelloworldApplication.class, args);
    }
}

Q:
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
A:
使用了自动配置的数据源,如generatorConfig.xml
添加过滤操作 @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class ,scanBasePackages={"com.simple.helloworld.mapper"})
@MapperScan("com.simple.helloworld.mapper")
public class HelloworldApplication {
    public static void main(String[] args) {
        SpringApplication.run(HelloworldApplication.class, args);
    }
}

Q:
Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

A:

@Service
public abstract class CityMapper extends SqlSessionDaoSupport {
    @Override
    @Autowired
    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
        super.setSqlSessionFactory(sqlSessionFactory);
    }
}
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class ,scanBasePackages={"com.simple.helloworld.mapper"})
@MapperScan("com.simple.helloworld.mapper")
public class HelloworldApplication {
    public static void main(String[] args) {
        SpringApplication.run(HelloworldApplication.class, args);
    }
}

相关文章

  • 接口编写

    这里写接口用的Python3,用的flask+pymysql.cursors 导入mysql文件 appstore...

  • 接口编写

    最简单的编写 新建 DemoRestController pom.xml 添加依赖 点击右上角运行 验证在浏览器或...

  • 一键生成 API 文档的妙招

    一般接口文档编写完成后,就要开始编写调用接口的代码,很多开发团队都采用传统的通过接口文档的方式来编写接口。但在接口...

  • 测试平台系列(20) 编写项目的增删改查接口和页面(2)

    回顾 上回说到,编写项目权限相关接口,但是我们只完成了核心方法的编写,这次我们就来定义相关的接口。 编写接口 先实...

  • 接口文档的编写

    参考资料 如何优雅的格式化接口 如何优雅的“编写”api接口文档 接口文档的编写

  • java的三种代理

    代理 静态代理 编写需要目标对象实现的接口 编写目标类,实现接口 编写静态代理类,也需要实现该接口 需要维护一个接...

  • Java如何实现一个动态代理

    1.编写两个接口 UserDao PersonDao 2.编写两个接口的实现类 UserDaoImpl 3.编写任...

  • Django项目使用Swagger自动生成API文档

    简介 接口开发完成了,那么接下来需要编写接口文档。传统的接口文档编写都是使用word或者其他一些接口文档管理平台,...

  • 接口文档编写

    一.什么是接口 API(Application Programming Interface)即应用程序接口,可以任...

  • node接口编写

网友评论

      本文标题:接口编写

      本文链接:https://www.haomeiwen.com/subject/fxgrsqtx.html