前端 vue(vscode)
后端 springboot(idea)
我们是axios
配置路由: src/router/index.js
基础知识:
springboot注解
-
@Component
- 作用:告知Spring帮我们管理这个对象
- 放置位置:类上
-
@Controller、@Service、@Repository
- 作用:与Component
- 放置位置:类上
- 这样写更能体现出分层架构的思想,@Controller注解用于管理控制层的对象,@Service注解用于管理model层中的service层的对象,@Repository用于管理model层中的dao层的对象
-
@Autowired
- 作用:自动装配
- 放置位置:属性上、构造方法上、set方法上
-
@Qualifier
- 作用:配合Autowired使用,用来指定具体注入的对像的唯一标识
-
@Resource(name="")
- 等同于Autowired和Qualifier的结合使用
- 它不是Spring框架的注解
-
@Scope
- 作用:声明对象的作用域,
- singleton
- prototype
- 放置位置:类上
-
@Lazy
- 作用:声明该对象是否启用懒加载机制
- 放置位置:类上
-
@Value()
- 作用:给属性注入值
- 放置位置:属性上
-
@PostConstruct
- 作用:当对象实例化之后,第一次执行的方法
-
@PreDestroy
- 作用:当对象被销毁后,第一次执行的方法
-
@Bean
- 作用:通过方法产生一个对象交给Spring去管理
- 放置位置:方法上面
-
@Configuration
- 作用:声明该类是Spring的核心配置类(等同于Spring的核心配置文件),
- 放置位置:类上面
-
@ComponentScan
- 作用:告知Spring哪些包是需要扫描的(扫描需要被Spring管理的对象)
- 放置位置:类上面
-
@PropertySource
- 作用:引入一个外部.properties文件
- 放置位置:类上面
-
@Import
- 作用:引入其他配置类
- 放置位置:类上面
- @requestmapping 声明URL地址
- requestparam request 为true 就是必须要的 false 的话 就是非必须 value 可以用来对前端的取值进行命名统一 避免取不到值
一些目录结构功能:
注册axios和route路由: src/main.js
/设置反向代理,前端请求默认发送到 http://localhost:8443/api
var axios = require('axios')
axios.defaults.baseURL = 'http://localhost:8443/api'
//全局注册,之后可在其他组件中通过 this.$axios 发送数据
Vue.prototype.$axios= axios
配置跨域支持:让后端能够访问前端资源(vue.config.js)