
springboot
文章平均质量分 50
kiraraLou
这个作者很懒,什么都没留下…
展开
-
【SpringBoot】springboot使用RestTemplate 进行http请求失败自动重试
我们的服务需要调用别人的接口,由于对方的接口服务不是很稳定,经常超时,于是需要增加一套重试逻辑。这里使用的方式来实现。一、引入POM二、 修改启动类在Spring Boot 应用入口启动类,也就是配置类的上面加上注解,表示让重试机制生效。@Bean} }原创 2023-04-10 11:02:34 · 3177 阅读 · 0 评论 -
【springboot】springboot发送email(文本/html格式)邮件
前言现在发送邮件是一个网站必备的功能,比如注册激活,或者忘记密码等等都需要发送邮件。正常我们会用JavaMail相关api来写发送邮件的相关代码,但现在springboot提供了一套更简易使用的封装。也就是我们使用SpringBoot来发送邮件的话,代码就简单许多,毕竟SpringBoot是开箱即用的 ,它提供了什么,我们了解之后觉得可行,就使用它,自己没必要再写原生的。实践导入依赖pom.xml<dependency> <groupId>org.springfram原创 2021-12-23 17:57:21 · 2597 阅读 · 0 评论 -
【Thymeleaf】Thymeleaf springboot配置
前言最近需要发送邮件,然后需要使用Thymeleaf来生成HTML文件。实践1. pom.xml 文件 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <原创 2021-12-23 17:46:32 · 583 阅读 · 0 评论 -
【Thymeleaf】获取Thymeleaf的当前日期
前言直接使用Thymeleaf获取当前时间,并进行格式化实施添加pom文件 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <group原创 2021-12-23 15:22:32 · 4402 阅读 · 0 评论 -
【MyBatis】MyBatis中if标签正确使用方法(Integer类型)
前言持久层:MyBatis组合查询一组数据,字段有:String Integer 类型。由于字段都可能为空,所以mapper文件中这样写的:实践<select id="selectIndexAvgStore" resultMap="IndexShardNumCheck" useCache="false" flushCache="true"> <include refid="selectShardNumCheck"/> <where&g原创 2021-12-21 18:06:07 · 3154 阅读 · 0 评论 -
【springboot】springboot接收不同的Content-Type类型请求
1. Content-Type:application/jsonapplication/json:是以json字符串的格式请求springboot中 application/json:只能以@requestBody注解接收对象Postman请求示例:后台示例:@PostMapping(value = "/asset", produces = Constants.APPLICATION_JSON_UTF) public AssertResultEntity Assets(@Requ原创 2021-10-22 16:42:13 · 4434 阅读 · 1 评论 -
【springboot】springboot传入JSON对象参数
前言:在使用springboot 传入JSON对象参数时,需要注意以下几点。请求参数格式必须是正确的JSON。在入参中使用注解@RequestBody,用于接收JSON参数,使其自动转对象标识请求参数的格式为JSON—>> @PostMapping(value="/Test",produces = "application/json;charset=UTF-8")具体实现1.后端代码@RestController@RequestMapping("/Test")p原创 2021-10-12 15:06:55 · 6339 阅读 · 0 评论 -
【springboot】class path resource [mybatis/mybatis-config.xml] cannot be opened because it does not ex
问题描述使用springboot 加载mybatis 配置文件,报错找不到该配置文件。报错内容:Caused by: java.io.FileNotFoundException: class path resource [mybatis/mybatis-config.xml] cannot be opened because it does not ex at org.springframework.core.io.ClassPathResource.getInputStream(ClassPa原创 2021-10-12 15:00:08 · 11840 阅读 · 0 评论 -
【springboot】转载 springboot接口入参下划线转驼峰以及返回参数驼峰转下划线实现
一、前言通常使用java来进行实际开发中,里面的变量都是使用驼峰的命名规则;但是有时候在对接其他三方平台的接口时,要求使用下划线的命名规则,这时候就涉及到如何让自己的接口满足三方平台的下划线;实现方式有:java里面也使用下下划线的方式接收和响应,但是不推荐这样,因为虽然满足了接口需求,但是不符合java里面的命名规范;2.j ava里面使用驼峰,接收到参数后手动转换,这样做太麻烦.java里面使用驼峰,写一个工具方法,通过注解的方式,统一转换,推荐,也是实际开发中常用的方式那些地方需原创 2021-10-12 13:52:51 · 1348 阅读 · 0 评论 -
【springboot】@RequestParam参数使用
@RequestParam使用defaultValue属性设置默认值注意设置必须是string类型的,框架自己会做转换案例如下:@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,@RequestParam(value = "size", required = false) Integer size,...原创 2021-07-30 13:38:58 · 1822 阅读 · 0 评论 -
【springboot】@PathVariable注解使用
@PathVariable获取URI地址中的参数值,需要结合URI模板映射@PathVariable会将数据放到模型中,界面可以通过el表达式获取(即浏览器上面可以显示出来),但是@RequestParam不能通过界面获得如何使用@DeleteMapping (value ="/group/{groupId}" )public AjaxResult deleteBigDataGroup(@PathVariable Integer groupId) { AjaxResult a.原创 2021-06-07 10:14:25 · 241 阅读 · 0 评论 -
【Mybatis】useGeneratedKeys参数用法及遇到的问题
什么是useGeneratedKeys?官方的说法是该参数的作用是:“允许JDBC支持自动生成主键,需要驱动兼容”,如何理解这句话的意思?其本意是说:对于支持自动生成记录主键的数据库,如:MySQL,SQL Server,此时设置useGeneratedKeys参数值为true,在执行添加记录之后可以获取到数据库自动生成的主键ID。如何使用?可以通过如下的方式来实现配置:配置全局的配置文件在xml映射器中配置useGeneratedKeys参数在接口映射器中设置useGeneratedKe原创 2021-06-04 18:50:38 · 18349 阅读 · 7 评论 -
【springboot】Springboot读取别的配置文件
前提springboot项目需要读取非application.yml/properties 的配置文件。操作步骤新建配置文件编辑配置文件test-server=rd-dev02.jr.rong360.com新建Config类@Component@PropertySource(value = "kirara.properties")public class KiraraConfig { @Value("${test-server:rd-dev02.jr.rong360.原创 2021-05-27 14:06:58 · 477 阅读 · 0 评论 -
【springboot】SpringBoot配置logback.xml 多环境
前提logback日志文件要实现springboot多环境配置,不然每次都需要修改logback.xml里面的配置文件,所以很麻烦。操作步骤resource文件的内容结构如下:配置application.ymlspring: profiles: active: devlogging: config: classpath:logback-${spring.profiles.active}.xml配置lockback-dev.xml这个地方就可以实现自己的原创 2021-05-27 11:39:58 · 749 阅读 · 1 评论 -
【springboot】springboot读取application配置文件
项目需求项目需要读取application.yml中自定义的配置文件。跨工程也是可以读取到application.yml文件的配置内容的读取方式@ValueEnvironment方式一:使用@Value方式(常用)核心配置文件application.yml内容如下:# 自定义配置项uuap: server: host: 10.12.16.84 systoken: 39ca7b2c849b85d1 sysname: sitonya代码示意:@Serv原创 2021-05-27 11:17:19 · 1954 阅读 · 1 评论 -
[Postman]postman调试接口报错整理
问题一:在做spring boot项目时用postman进行json调用测试时出现以上错误:这表达的意思是说上下文的类型格式不对,后台要求为json格式,而上传的是text/plain格式。所以将调用路径的header加上key Content-Type,value为application/jsonorg.springframework.web.HttpMediaTypeNotSupportedException: Content type 'text/plain;charset=UTF-8'解原创 2021-05-27 10:19:45 · 6959 阅读 · 0 评论