springboot
Mai JH
这个作者很懒,什么都没留下…
展开
-
fastjson
//DTO对象转换为Json格式 通常作为数据PostJSON.toJSONString(accessTokenDTO//Json格式转换为DTO对象 GithubUser githubUser = JSON.parseObject(string, GithubUser.class);原创 2020-07-25 11:41:37 · 88 阅读 · 0 评论 -
设置Cookie过期时间
Cookie cookie = new Cookie("token", token); cookie.setMaxAge(60 * 60 * 24 * 30 ); //30天 response.addCookie(cookie);原创 2020-07-25 10:21:25 · 212 阅读 · 0 评论 -
简单搜索功能的实现
利用Mybatis的动态sql数据库正则查找Regx |前端将搜索内容发送到后端<form class="navbar-form navbar-left" action="/" method="get"> <div class="form-group"> <input type="text" class="form-control" name="search" placeholder="搜索问题"> </div>原创 2020-07-25 09:18:11 · 1166 阅读 · 0 评论 -
Stream 获取去重 转换Map 数据转换
// 获取去重的评论人 Set<Long> commentators = comments.stream().map(comment -> comment.getCommentator()).collect(Collectors.toSet()); List<Long> userIds = new ArrayList<>(); userIds.addAll(commentators); // 获取评论人并转换成Map .原创 2020-07-25 08:51:43 · 1140 阅读 · 1 评论 -
logout退出登录实现
@GetMapping("/logout")publish String logout(HttpServletRequest request,HttpServletResponse response){ //获取session对象后移除"user" request.getSession().removeAttribute("user"); //获取指定cookie并删除 Cookie cookie = new Cookie("tkone","null"); cookie.setMaxAge(0)原创 2020-07-25 08:48:13 · 1285 阅读 · 0 评论 -
Mybatis-generator避免覆盖自定义的sql方法
编写PersonExtMapper.java 接口文件 编写自定义方法编写PersonExtMapper.xml 映射文件 配置映射PersonExtMapper.xml 和PersontMapper.xml(Mybatis生成器生成)的区别指向各自的Maper接口文件但 相同当数据库字段发生改变 执行指令mvn -Dmybatis.generator.overwrite=true mybatis-generator:generate 不会覆盖自定义的方法...原创 2020-07-24 20:46:10 · 1293 阅读 · 0 评论 -
Springboot 多配置properties启动项目
查看application.propertiesmore src/main/resource/application.properties创建application-production.propertiescp src/main/resource/application.properties src/main/resource/application-production.properties编写 production的配置文件(避免修改application.properties)vim s原创 2020-07-24 20:17:34 · 238 阅读 · 0 评论 -
Springboot部署maven profile 环境配置 隐藏信息
使用指定环境配置mvn clean compile flyway:migrate -Pdev mvn clean compile flyway:migrate -Pproduction clean 清除 compile编译 package打包Maven官网关于profile标题 在服务器上创建 ~/.m2/seeting.xml如下:setting.xml中的profiles 配置数据库连接信息 达到隐藏信息作用 <profiles> <profi原创 2020-07-24 20:15:18 · 408 阅读 · 1 评论 -
SpringBoot 默认日志
Spring boot 默认使用Logback 作为日志系统,默认只在控制台显示By default, if you use the “Starters”, Logback is used for logging. --Spring.io原话日志级别 Log Level: ERROR, WARN, INFO, DEBUG, or TRACE. 等级顺序升高 作用: 如设置INFO 则显示ERROR, WARN, INFO. 其他类同想要输出文件就要添加以下属性 loggin原创 2020-07-24 18:35:15 · 381 阅读 · 0 评论 -
SpringBoot事务不回滚,不生效
常见坑点1:遇到检测异常时,事务默认不回滚。SQLException原因分析:因为Spring的默认的事务规则是遇到运行异常(RuntimeException及其子类)和程序错误(Error)才会进行事务回滚,显然SQLException并不属于这个范围。如果想针对检测异常进行事务回滚,可以在@Transactional 注解里使用rollbackFor 属性明确指定异常。例如下面这样,就可以正常回滚 @Transactional(rollbackFor = Exception.class)常见原创 2020-07-06 19:47:03 · 1745 阅读 · 0 评论