基于springboot搭建web项目遇到的问题汇总
2018-07-23 14:40
621 查看
1.application类要放在最外层的package下;
2.整合mybatis时,@MapperScan注解要扫描到mapper包,不然调不到
[code]@SpringBootApplication @MapperScan("com.test.mapper") public class TestApplication { public static void main(String[] args) { SpringApplication.run(TestApplication .class); } }
3.@RestController = @Controller + @ResponseBody:
1)@RestController:方法返回值自动转为json,若想返回模板要使用@Controller
2)@Controller:方法返回模板,若要返回json需在方法上加@ResponseBody
[code]@Controller public class AnimeController { // 返回index模板 @RequestMapping("/index_1") public String index_1() { return "index"; } // 返回“index”字符串 @ResponseBody @RequestMapping("/index_2") public String index_2() { return "index"; } } @RestController public class AnimeController { // 返回“index”字符串 @RequestMapping("/index") public String index() { return "index"; } }
4.前端使用vue+elementUI,启动端口8080,后端启动端口8081,前台发送请求后台接收不到,需要前端配置project\config\index.js
[code] proxyTable: { '/api': { target: 'http://localhost:8081', //域名 changeOrigin:true, pathRewrite:{ '^/api':'' } } }
发送请求为:/api/xxx
阅读更多相关文章推荐
- IDEA上面搭建一个SpringBoot的web-mvc项目遇到的问题
- 基于多个maven module搭建的Spring boot web项目
- 搭建springMVC+Mybatis的Maven项目过程中遇到的问题汇总。
- 基于SpringBoot + Mybatis实现SpringMVC Web项目
- 如何基于Spring Boot搭建一个完整的项目
- IDEA上面搭建一个SpringBoot的web-mvc项目
- Spring-Boot快速搭建web项目详细总结
- idea+maven+springboot搭建web简单项目经历小计(RestController)
- 基于SpringBoot + Mybatis实现SpringMVC Web项目【原创】
- 用Spring Boot搭建简单web项目
- 遇到问题---maven---启动项目出现出现 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoa
- 【Web前端】Vue.js 项目中遇到的一些问题汇总
- 创建spring boot项目启动报错遇到的问题
- 《Gradle构建SpringBoot学习笔记》第二章:创建基于Gradle构建的Spring Boot Web项目
- 搭建基于springboot的SSM项目时数据库出现的错误解决
- SpringBoot项目Web应用搭建
- springboot学习1-使用 Spring Starter Project快速创建基于spring-boot的web项目
- 基于Maven的Springboot项目搭建学习笔记
- java 搭建基于springboot的ssh(spring + springmvc + hibernate)的gradle项目(基础篇)