跨度太大,无法完成,遂决定从基础学起。
规划路线:
1.完成JAVA与c++语言差异部分,(注解,其实没多少)
2.上springboot官网查看开发手册,了解大致原理。
3. 开始挑选项目上手。
4.上手过程遇到困难再学别的。
1.无法连接数据库,springboot报错
hello函数用@GetMapping来激活
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "Tomato") String name) {
return String.format("Hello %s!", name);
}
}
后端的请求使用https, 返回形式为
code
msg
data
这里需要将返回的数据用几个方法统一封装起来
使用方法:serializable.
有些方法我没有实现,不知道为什么就能用了,如setCode
跨域的函数得用另一个,但是换回来之后又没问题了,所以两个都是通用的
/CorsConfig.java
package com.markerhub.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* 解决跨域问题
*/
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
..allowedOrigins("*")//这个需要修改 --》 .allowedOriginPatterns("*")
.allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
.allowCredentials(true)
.maxAge(3600)
.allowedHeaders("*");
}
}