接口编写

最简单的编写

屏幕快照 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);
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,449评论 0 10
  • 今天做两个小结,一个是关于房地产讨论的小模块的,一个是关于整个价格理论大大模块的。 哈罗德-得姆塞斯在讨论到价格的...
    尘世书童阅读 500评论 0 0
  • 第五十七回,慧紫鹃情辞试忙玉,兹姨母爱语慰痴颦 宝玉去看黛玉,刚好黛玉睡着了。他看紫鹃正在做针线活,伸手便去摸紫鹃...
    清荷沐阳阅读 825评论 0 2
  • 这就是苏格拉底的作风,在任何地方跟任何人聊天,只要聊到一个重要的词,这个词牵涉到人的行为,牵涉到人的德行的,他一定...
    池浅笑安然阅读 163评论 0 0