基本的Spring Boot环境已经构建好了,下面需要配置Spring框架及SpringMVC框架的业务环境
方法/步骤
1
@ComponentScan注解
2
默认扫描默认扫描当前包com.atguigu.crowdfunding和子包com.atguigu.crowdfunding.*如果还需要扫描其他的包,那么需要增加@ComponentScan注解,指定包名进行扫描。
3
增加控制器代码在src/main/java目录中增加类com.atguigu.crowdfunding.controller.MemberController,并增加相应代码。
4
执行main方法启动应用l 访问路径http://127.0.0.1:8080[/应用路径名称]/member/index 页面打印JSON字符串即可
5
@Controller和@RestController区别官方文档:@RestController is a stereotype annotation that combines @ResponseBody and @Controller.表示@RestController等同于@Controller + @ResponseBody,所以上面的代码可以变为:
6
增加服务层代码Service接口,ServiceImpl实现类的使用和SSM架构中的使用方式完全相同。