springboot使用研究

server/2024/9/22 23:34:07/
map-underscore-to-camel-case: true

开启驼峰命名

   @GetMapping("/userInfo")public Result<Users>  userInfo(@RequestHeader(name = "Authorization") String token,HttpServletResponse  response) {Map<String, Object> map = JwtUtil.parseToken(token);
//        System.out.println(","+map.get("user")+"."+map.get("user"));String username =(String) map.get("username");Users u = usersService.findByUserName(username);return Result.success(u);}

threadlocal

相当于全局变量

//全局变量 全局共享变量
public class ThreadLocalUtils {private static ThreadLocal THREAD_LOCAL = new ThreadLocal();
//    根据键值对取值public static <T> T get() {return (T)THREAD_LOCAL.get();}
//    存储键值对public static void set(Object o) {THREAD_LOCAL.set(o);}
//    清除 防止内存泄露public static void remove() {THREAD_LOCAL.remove();}
}

线程安全的

// 根据用户名查询@Select("select * from users where username=#{username}")Users findByUserName(String username);//    添加注册
//    @Insert("insert into users(username,password,create_time,update_time) values(#{username},#{possword},now(),now())")
//    void add(String username, String possword);@Insert("insert into users(password,username) values(#{possword},#{username})")void add(@Param("possword")String possword, @Param("username")String username);@Select("select * from users where username=#{username} and password=#{possword}")Users find(@Param("username")String username, @Param("possword")String possword);@Update("update users set nickname=#{nickname},email=#{email},update_time=#{updateTime} where id=#{id}")void update(Users u);

Notnull  不能为null

notempty 不能为null并且不能为空

emai  email格式校验

@validated 满足的实体进行生效

@pattern

添加validated才能够生效

@URL 判断是否为url地址

    @Update("update users set password=#{newpwd},update_time=now() where id=#{id}")void updatePwd( @Param("newpwd")String newpwd, @Param("id") Integer id);
     <dependency><groupId>javax.persistence</groupId><artifactId>persistence-api</artifactId><version>1.0</version></dependency>

添加依赖  使用

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
 
@Entity
public class ExampleEntity {
    @Id
    private Long id;
 
    @Column(name = "\"order\"") // 使用双引号来包围关键字
    private String order;
 
    // 省略getter和setter
}

使用redis进行token失效  主动失效

集成redis

  <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency>

  data:redis:host: 127.0.0.1port: 6379

//这个注解,单元测试执行之前,先初始化这个容器
@SpringBootTest
public class redistest {@Autowiredprivate StringRedisTemplate stringRedisTemplate;@Testpublic  void test(){
//        向redis中添加键值对ValueOperations<String,String> valueOperations =  stringRedisTemplate.opsForValue();valueOperations.set("username","world");
//        秒过期valueOperations.set("id","1", 15,TimeUnit.SECONDS);
//        String hello = valueOperations.get("username");
//        System.out.println(hello);}@Testpublic  void gettest(){
//        向redis中添加键值对ValueOperations<String,String> valueOperations =  stringRedisTemplate.opsForValue();
//        valueOperations.set("username","world");String hello = valueOperations.get("id");System.out.println(hello);}
}

redis的操作


//                删除redis某个keyValueOperations<String,String> val = stringRedisTemplate.opsForValue();val.getOperations().delete("token");
   String token1 = stringRedisTemplate.opsForValue().get("token");if(token1==null){throw new RuntimeException();}else{}

拦截器拦截中的token判断

 <groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>${spring-boot.version}</version>

打包jar包

打包

打包之后的位置

jar -jar jar包名称

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-resources-plugin</artifactId><version>3.1.0</version>
</plugin>
    <plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-resources-plugin</artifactId><version>3.1.0</version></plugin>

打包用的配置plugin

改为false

修改端口   java -jar big.jar  --server.port=9999


http://www.ppmy.cn/server/39233.html

相关文章

【深度学习】第二门课 改善深层神经网络 Week 1 深度学习的实践层面

&#x1f680;Write In Front&#x1f680; &#x1f4dd;个人主页&#xff1a;令夏二十三 &#x1f381;欢迎各位→点赞&#x1f44d; 收藏⭐️ 留言&#x1f4dd; &#x1f4e3;系列专栏&#xff1a;深度学习 &#x1f4ac;总结&#xff1a;希望你看完之后&#xff0c;能对…

使用Gin编写Web API项目并自动化文档

最近需要使用Go写一个Web API项目&#xff0c;可以使用Beego与Gin来写此类项目&#xff0c;前文使用Beego创建API项目并自动化文档介绍了使用Beego来创建的Web API项目并自动化文档的方法。本文就介绍一下使用Gin来编写Web API项目并自动化文档。 一、创建项目 在创建Beego项…

LearnOpenGL(九)之材质

一、材质 在现实世界里&#xff0c;每个物体会对光产生不同的反应。比如&#xff0c;钢制物体看起来通常会比陶土花瓶更闪闪发光&#xff0c;一个木头箱子也不会与一个钢制箱子反射同样程度的光。在opengl中&#xff0c;我们可以针对每种表面定义不同的材质(Material)属性来模…

今日分享【CSS中的经典使用】

经典双飞翼布局 先看效果 双飞翼布局要求&#xff1a; 1、header和footer各自占领屏幕所有宽度&#xff0c;高度固定。 2、中间的container是一个三栏布局。 3、三栏布局两侧宽度固定不变&#xff0c;中间部分自动填充整个区域。 4、中间部分的高度是三栏中最高的区域的高度。…

OBS插件--计时器

计时器 计时器使用文本源作为内容显示的区域,可以设置字体、颜色等。支持倒计时和到指定时间的计时&#xff0c;可以设置计时结束显示消息、场景切换等。 下面截图演示下操作步骤&#xff1a; 首先&#xff0c;打开 OBS直播助手 在插件中心左侧导航栏&#xff0c;选择 工具…

Linux-笔记 i2c-tools

1、i2c-tools介绍 1、在日常linux开发中&#xff0c;有时候需要确认i2c硬件是否正常连接&#xff0c;设备是否正常工作&#xff0c;设备的地址是多少等等&#xff0c;这里我们就需要使用一个用于测试I2C总线的工具——i2c-tools&#xff0c;i2c-tools原理是通过操作/dev 路径 …

this application requires .NET Framework 4.5.2

安装mysql社区版的时候报这个错&#xff1a;this application requires .NET Framework 4.5.2 https://www.microsoft.com/en-us/download/details.aspx?id42642

rk3588局域网推流

最近无意间看见在网上有使用MediaMtx插件配合ffmpeg在Windows来进行推流&#xff0c;然后在使用其他软件进行拉流显示数据图像的&#xff0c;既然windows都可以使用 &#xff0c;我想linux应该也可以&#xff0c;正好手上也有一块RK3588的开发板&#xff0c;就测试了一下&#…