springboot访问后端静态资源404
在使用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/"); } }
其次可能你书写的路径不属于默认访问路径
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 方法 }
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论