-
How to convert properties and yaml files to each other
Install plug-ins -
The difference between the properties file and the yaml file
The properties file is assigned by "." and "=", without a space before the value, and the yaml is assigned by ":", and a space is added before the value; the yaml file is indented with a space; properties only support key-value
pairs , The yaml configuration file supports a list, and the dash indicates the list "-";
properties does not guarantee the loading order, and yaml has a sequence; -
Will the program automatically read the yaml file? Do you need to configure it?
-
The difference between restcontroller and controller
-
Error reporting without restcontroller
Error resolving template [], template might not exist or might not be accessible by any of the conf
-
@Requestpart,@RequestBody,@RequestParam
-
@RequestBody is mainly used to receive the data in the json string passed from the front end to the backend (data in the request body); and the most commonly used request body to pass parameters is undoubtedly the POST request, so when using @RequestBody to receive data , usually submitted by POST. In the same receiving method of the backend, @RequestBody and @RequestParam() can be used at the same time, @RequestBody can only have one at most, and @RequestParam() can have multiple.
9. postman pass file and object parameters at the same time
-
How to pass objects in get requests
Just use RequestBody just like Post requests -
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.NullPointerException: Cannot invoke "String.length()" because "s" is null] with root cause
The reason is that the object calling the length method is empty, and the file name passed in was read from the database, but I forgot to save the file name in the database. -
Cannot call sendError() after the response has been committed
The literal meaning is that the response was called twice, resulting in the inability to call the sendError method. -
No converter for [class com.seed5.ocs.model.Respond] with preset Content-Type 'application/octet-stream'
Change the return value type of the controller to void
response.reset()
But I used response.reset doesn't seem to work.
The case is solved, response.reset()
the reason why using the function does not work is
InputStream inputStream=new FileInputStream(file)
//我这里的file参数是File类型,实际应该传入String类型的path
No case was solved, so what was the reason?
-
2021 IDEA discontinued compiler.automake.allow.when.app.running
-
npm ERR! { Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_cache\_locks'
-
What is the parameter res in the success.function.res() callback function of the request when the front-end and back-end interfaces are connected?
-
Cross-domain problems when front-end and back-end docking
-
The backend returns a unified result to the frontend,
establishes a format
, defines common errors, enumerates
tool classes, and writes return information -
Various correspondences between axios sending requests and SpringBoot receiving requests
-
The role of the vue $ symbol
Vue 实例还暴露了一些有用的实例属性与方法,它们都有前缀 $,以便与用户定义的属性区分开来
is to mount the attributes on vue -
this.$message()
-
Cross-domain problem
Cross-domain resource request problem, inevitable problem of front-end and back-end separation projects
Same domain: same protocol, same port number, same host
CORS, set in the backend, create a new configuration class to allow cross-domain requests.
@Configuration
public class CorsConfig implements WebMvcConfigurer{
@Override
public void addCorsMappings(CorsRegistry registry){
registry.addMapping("/**")//允许跨域访问的路径
.allowedOrigins("*")//允许跨域访问的源
.allowedMethods("POST","GET","PUT","OPTIONS","DELETE")//允许跨域访问的方法
.maxAge(168000)//预检间隔时间
.allowedHeaders("*")//允许头部设置
.allowCredentials(true);//是否允许发送cookie
}
}
Modify the response header
jsonp
and report a line error.
When allowCredentials is true, allowedOrigins cannot contain the special value "*" since that cannot be set on the "Access-Control-Allow-Origin" response header. To allow credentials to a set of origins, list them explicitly or consider using "allowedOriginPatterns" instead.
This is because the AllowedOrigin setting has changed when springboot is upgraded to 2.4.0 or above, and there cannot be "*"
Solution: Cross-domain configuration error, just replace .allowedOrigins with .allowedOriginPatterns.
@Configuration
public class CorsConfig implements WebMvcConfigurer{
@Override
public void addCorsMappings(CorsRegistry registry){
registry.addMapping("/**")//允许跨域访问的路径
// .allowedOrigins("*")//允许跨域访问的源
.allowedOriginPatterns("*")
.allowedMethods("POST","GET","PUT","OPTIONS","DELETE")//允许跨域访问的方法
.maxAge(168000)//预检间隔时间
.allowedHeaders("*")//允许头部设置
.allowCredentials(true);//是否允许发送cookie
}
}
-
The scope of the JS callback function sends changes.
Use the arrow function (the network request callback function)
this.data is equivalent to this=>name -
No converter for [class com.seed5.ocs.model.ReturnRestful] with preset Content-Type 'application/octet-stream'
application/octet-streamWhen a browser requests a resource, it will determine how to display/process the data to be loaded through the content-type in the http return header. If this type of browser can support browsing, the browser will directly display the resource, such as png, jpeg , video and other formats. In some scenarios of downloading files, the server may return the file stream with Content-Type: application/octet-stream in the return header, telling the browser that this is a byte stream, and the browser The default method for streaming is to download .
Application/octet-stream is the default for application files. It means an unknown application file, and the browser generally does not automatically execute or ask for execution. The browser will treat this type of file as if it sets the HTTP header Content-Disposition value as attachment, that is, the browser will trigger the download behavior.
In other words, the browser does not know what type it is, nor how to display it. It only knows that it is a binary file, so when it encounters a file whose content-type is application/octet-stream, the browser will Download it directly . This type generally cooperates with another response header, Content-Disposition, which indicates in what form the content of the reply should be displayed, whether it is inline (that is, a web page or part of a web page), or downloaded and saved as an attachment. local.
Explain the source
So is this returned parameter also regarded as the content to be downloaded by the browser? So there is no way to convert the return parameter type to a binary type.The currently known and effective solution to this problem is: set the function to a void function (do not set the return value type).
But if it is set before the response is submitted, there is no way to submit the binary stream, and if it is set afterward, an error will be reportedCannot call reset() after response has been committed
-
File deletion
Universal file deletion method in java -
log
private static final Logger log = LoggerFactory.getLogger(homeworkController.class);
-
Rich Text Editor
I want to build a rich text editor that can edit, save, view, modify, and delete content. -
The correspondence between SpringBoot + Mybatis entity class attributes and database table column names
The problem looks like this
The solution is to do a mapping.
Mybatis solves the problem of inconsistency between database field names and entity class attribute names
My solution:
Turn on the hump naming rule:
modify mybaits-config.xml
and insert it in the settings tag
<setting name="mapUnderscoreToCamelCase" value="true"/>
-
How does postman view the content of the original http request and response (I want specific information such as Kangkang request first)
Click on the console, and then click on the specific request you want to view
-
"Content type 'application/octet-stream' not supported" error occurred in the request
-
The backend uses @RequestParam to pass files, and @RequestPart passes objects to upload objects and files at the same time. How should the frontend pass parameters?
After I turned the json object into a blob (binary array), the backend was still crazily reporting errors.
2023-04-06T23:42:12.512+08:00 WARN 9272 --- [nio-8443-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type
com.seed5.ocs.model.Studentworkfrom Array value (token
JsonToken.START_ARRAY)]
I don’t know if it’s a parsing problem or what’s going on. When passing it, the parameter is a json object. After passing it, the parameter becomes an array. The solution is to pass the @RequestParam
type parameter , packed into objects in the background. -
Turn on hump mapping
Add this sentence in the application.properties file
mybaits.configuration.map-underscore-to-camel-case:=true
and report an error:
Property 'configuration' and 'configLocation' can not specified with together
The solution
is that I already have the mybaits.xml file, so I can no longer configure it in application.properties,
but I found that I have actually configured it in the mybaits.xml file
Did not take effect
Reason: Manually configured database connection
Solution:
- After the terminal uses git clone to pull the maven project, open the project with IDEA, but the files are all .java files with yellow icons, and the blue class files cannot be displayed like new Java files, and cannot be run directly.
solution