- 在使用springboot访问后台静态资源时发生404错误原因在于前台配置的访问路径中可能包含了公共资源类的本级路径例如:在访问后天资源时加了"public/",“static/”,但在实例访问时不需要加载该级路径,通过配 WebMvcConfigurer解决
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("*")
.allowedMethods("GET", "HEAD", "POST","PUT", "DELETE", "OPTIONS")
.allowCredentials(true).maxAge(3600);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//开放static,templates,public 目录 但是请求时候需要加上对应的前缀,比如我访问static下的资源/static/xxxx/xx.js
registry.addResourceHandler("/static/**","/templates/**","/public/**")
.addResourceLocations("classpath:/static/","classpath:/templates/","classpath:/public/");
}
}
2.其次可能你书写的路径不属于默认访问路径
spring:
mvc:
static-path-pattern: /res/** #静态资源访问前缀为res
---
spring:
resources:
static-locations: [classpath:/res/] #在类路径的res文件夹下的静态资源才能被访问到
mybatis中默认的驼峰命名转下划线
默认情况下,MyBatis 会将实体类的属性名转换为小写,并将驼峰命名法转换为下划线命名法,然后与数据库表的列名进行匹配。如果您有一个名为 User
的实体类,它有一个名为 userName
的属性,那么 MyBatis 默认会将它映射为数据库表中的 user_name
列
@Id
是 MyBatis 中的一个注解,用于标识实体类中的属性作为表的主键。在 MyBatis 中,如果您要使用 @Id
注解来标识主键属性,还需要使用 @GeneratedValue
注解来指定主键的生成方式。
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String username;
private String password;
// 省略 getter 和 setter 方法
}