家庭记账本2

后端使用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

 

posted on 2024-02-21 23:23  Daniel350  阅读(30)  评论(0编辑  收藏  举报