后端使用springboot+mybatisPlus+mysql
建立数据库并建表
确定项目结构
解决跨域访问问题CorsConfig.java
@Configuration public class CorsConfig { // 当前跨域请求最大有效时长。这里默认1天 private static final long MAX_AGE = 24 * 60 * 60; @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration corsConfiguration = new CorsConfiguration(); corsConfiguration.addAllowedOrigin("*"); // 1 设置访问源地址 corsConfiguration.addAllowedHeader("*"); // 2 设置访问源请求头 corsConfiguration.addAllowedMethod("*"); // 3 设置访问源请求方法 corsConfiguration.setMaxAge(MAX_AGE); source.registerCorsConfiguration("/**", corsConfiguration); // 4 对接口配置跨域设置 return new CorsFilter(source); } }
application.properties
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/notes spring.datasource.username=root spring.datasource.password=1234 #??mybatis???????????? mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl server.port=9090 #??mybatis??????? mybatis.configuration.map-underscore-to-camel-case=true
标签:corsConfiguration,spring,家庭,source,记账,datasource,mysql,mybatis From: https://www.cnblogs.com/daniel350-wang/p/18036096