您的位置:首页 > 编程语言 > Java开发

基于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

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: