SpringBoot 项目笔记

  1. 使用lombok成员方法输出日志
@SpringBootApplication
@Slf4j
public class ReggieTakeOutApplication {
public static void main(String[] args) {
SpringApplication.run(ReggieTakeOutApplication.class, args);
log.info("程序运行开始");
}
}
  1. 配置mybatis和数据库不同命名规则映射关系
mybatis-plus:
global-config:
db-config:
id-type: assign_id
configuration:
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  1. 放行前端静态资源
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/backend/");
registry.addResourceHandler("/front/**").addResourceLocations("classpath:/front/");
}
}
  1. md5加密
    参考:https://blog.csdn.net/qq_41437844/article/details/121120227
password = DigestUtils.md5DigestAsHex(password.getBytes());
  1. 过滤器
// 引导类添加注解
@ServletComponentScan
// LoginCheckConfig
@WebFilter(filterName = "logCheckFilter", urlPatterns = "/*")
public class LogCheckFilter implements Filter {
public AntPathMatcher pathMatcher = new AntPathMatcher();
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
// 转换类型
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
// 获取uri
String uri = request.getRequestURI();
// 判断是否可以直接放行
String[] uris = new String[]{
"/employee/login",
"/employee/logout",
"/backend/**",
"/front/**"
};
// 不需要拦截,直接放行
if (check(uris, uri)) {
filterChain.doFilter(request, response);
return;
}
// 需要拦截,判断是否登录
if (request.getSession().getAttribute("employee") != null) {
filterChain.doFilter(request, response);
return;
}
// 未登录,且需要拦截,返回提示错误信息
response.getWriter().write(JSON.toJSONString(R.error("NOTLOGIN")));
return;
}
public boolean check(String[] uris, String uri) {
// 遍历数组
for (String u : uris) {
boolean match = pathMatcher.match(u, uri);
if (match) {
return true;
}
}
return false;
}
}
  1. No primary or single unique constructor found for interface java.util.List
    参考:https://blog.csdn.net/weixin_43404791/article/details/105664692

posted on   朝朝暮Mu  阅读(298)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示