码迷,mamicode.com
首页 > 编程语言 > 详细

Java后端开发——根据token写日志代码示例

时间:2020-03-12 23:26:08      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:用户信息   exception   信息   The   download   repr   ppi   head   ops   

@GetMapping("download/result")
@ApiOperation("提供手机号绑定结果给浏览器下载")     //Controller层代码

public Response<Boolean> downloadResultExcel(HttpServletRequest request) throws IOException {

  String token = request.getHeader("Authorization");

  return excelService.downloadResultExcel(token);

}

 


// @GetMapping("download/result") // @ApiOperation("提供手机号绑定结果给浏览器下载")         public Response<Boolean> downloadResultExcel(String token)throws IOException {    //Service层代码 String userIdStr = this.redisService.get(token);    //调用redisService取得当前页面用户信息 User user = this.userMapper.selectById(userIdStr); if (user==null || user.getIsDelete()==1){        //判断该用户是否存在 return new Response<>("导出手机号绑定信息日志写入失败"); }else { if (operationLogService.addOperationLog(user.getId(),"导出手机号绑定信息成功",1).getCode().equals("500")){ return new Response<>("导出手机号绑定信息日志写入失败"); } } return new Response<>("",Response.SUCCESS_CODE,Boolean.TRUE); } }

 

附上redisService代码如下:

 

@Autowired
    private StringRedisTemplate stringRedisTemplate;

public String get(String key) {
    return this.stringRedisTemplate.opsForValue().get(key);
}

 

 

StringRedisTemplate代码如下:

 

package org.springframework.data.redis.core;

import org.springframework.data.redis.connection.DefaultStringRedisConnection;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

public class StringRedisTemplate extends RedisTemplate<String, String> {
    public StringRedisTemplate() {
        RedisSerializer<String> stringSerializer = new StringRedisSerializer();
        this.setKeySerializer(stringSerializer);
        this.setValueSerializer(stringSerializer);
        this.setHashKeySerializer(stringSerializer);
        this.setHashValueSerializer(stringSerializer);
    }

    public StringRedisTemplate(RedisConnectionFactory connectionFactory) {
        this();
        this.setConnectionFactory(connectionFactory);
        this.afterPropertiesSet();
    }

    protected RedisConnection preProcessConnection(RedisConnection connection, boolean existingConnection) {
        return new DefaultStringRedisConnection(connection);
    }
}

 

如果觉得上述内容还可以的话,可以扫描下方二维码进行赞赏哟~??????

技术图片

 

同时也可关注微信公众号获得更多个人分享~??????

技术图片

Java后端开发——根据token写日志代码示例

标签:用户信息   exception   信息   The   download   repr   ppi   head   ops   

原文地址:https://www.cnblogs.com/bobbycheng/p/11866241.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!