当前位置:网站首页>Ruiji takeout project (II)
Ruiji takeout project (II)
2022-06-25 09:42:00 【Cold Snowflakes】
front end
JSON object :
and JS Object difference :
JSON The property name of the object (key) Must be enclosed in double quotes .
and JavaScript Object except for property names with spaces 、 There is a hyphen in the middle - The property name of must be inside or outside double quotes , Other random .
Can't be in JSON Object , And in the JavaScript Objects can .
JSON character string :
To transfer data between the front end and the back end, you can use JSON, But what is actually being passed on is JSON character string , and JSON Objects cannot be passed directly .
JSON The string is in JSON On both sides of the object '
Formed string .
let JSONObject = {
"k1":"v1","k2":"v2"}; // JSON object
let JSONString = '{"k1":"v1","k2":"v2"}'; // JSON character string
JSON.parse
: take JSON character string Convert to JS object .JSON.stringify
: take JSON object Convert to JSON character string .
computed: Compute properties
this.$refs[formName].validate:
< template slot-scope=“scope” >
Respond to JSON Data custom serialization type
The entity class that encapsulates the response data
@Data
public class employee implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private String username;
private String name;
private String password;
private String phone;
private String sex;
private String id_number;
private Integer status;
private LocalDateTime create_time;
private LocalDateTime update_time;
private Long create_user;
private Long update_user;
}
/** * Object Converter : be based on jackson take Java Object to json, Or will json To Java object * take JSON It can be interpreted as Java The process of an object is called [ from JSON Deserialization Java object ] * from Java Object to generate JSON The process is called [ serialize Java Object to JSON] */
public class JackSonObjectMapper extends ObjectMapper{
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
public static final String DEFAULT_TIME_FORMAT = "HH:mm:ss";
public JackSonObjectMapper() {
super();
// No exception is reported when an unknown attribute is received
this.configure(FAIL_ON_UNKNOWN_PROPERTIES, false);
// When deserializing , Property does not exist
this.getDeserializationConfig().withoutFeatures(FAIL_ON_UNKNOWN_PROPERTIES);
SimpleModule simpleModule = new SimpleModule()
// Deserialization
.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT)))
.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT)))
.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT)))
// serialize Respond to JSON Data time , Change the serialization type of the following types
.addSerializer(BigInteger.class, ToStringSerializer.instance)
.addSerializer(Long.class, ToStringSerializer.instance) // take domain in Long Type field , Serialize to JSON when , Serialize to String
.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT)))
.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT)))
.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT)));
// Registration function module for example , You can add custom serializers and deserializers
this.registerModule(simpleModule);
}
}
stay WebMvcConfig Configuration class , make carbon copies extendMessageConverters
Method , Extended message converter .
/** * Expand mvc frame Message converter for * @param converters */
@Override
protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
log.info(" Extended message converter ....");
// establish Message converter object
MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();
// Set up Object Converter
messageConverter.setObjectMapper(new JackSonObjectMapper());
// Append to mvc In the converter collection of the framework , And put it in the first place
converters.add(0,messageConverter);
}
ThreadLocal
Use SpringBoot When the server is embedded , If after starting , The front page file has been modified , You need to restart the server at the back end , The front end clears the browser cache , Only in this way can it work .
ThreadLocal, yes Thread Local variables of .
When using ThreadLocal When maintaining variables ,ThreadLocal Provide a separate copy of the variable for each thread that uses the variable .
So each thread can independently change its own copy , It will not affect the copy corresponding to other threads .ThreadLocal Provide a separate storage space for each thread , It has the effect of thread isolation .
/** * be based on ThreadLocal Wrapper utility class */
public class BaseContext {
// ThreadLocal Is thread isolated
private static ThreadLocal<Long> threadLocal = new ThreadLocal<>();
// Store value
public static void setCurrentId(Long id){
threadLocal.set(id);
}
// Value
public static Long getCurrentId(){
return threadLocal.get();
}
}
// Use
Long empId = (Long) request.getSession().getAttribute("employee");
BaseContext.setCurrentId(empId);
metaObject.setValue("updateUser",BaseContext.getCurrentId());
Data table primary key
Why is the primary key of a data table not set to auto increment , The back end is inserting , There is no auto fill , Set the default value , But you get a value .
because mybatis-plus The default policy for primary key generation is :ASSIGN_ID
, This strategy will use snowflake algorithm to generate primary key automatically ID, The primary key type is Long or String.
Mybatis-plus Primary key generation policy
边栏推荐
- Cassava tree disease recognition based on vgg16 image classification
- Matplotlib plt Axis() usage
- A game WP
- 纳米数据世界杯数据接口,中超数据,体育数据比分,世界杯赛程api,足球比赛实时数据接口
- SQL高级
- Lvs-dr mode single network segment case
- Matplotlib decision boundary drawing function plot in Matplotlib_ decision_ Boundary and plt Detailed explanation of contour function
- Etcd教程 — 第四章 Etcd集群安全配置
- 【mysql学习笔记21】存储引擎
- CYCA少儿形体礼仪 乐清市培训成果考核圆满落幕
猜你喜欢
Title B of the certification cup of the pistar cluster in the Ibagu catalog
Simple waterfall effect
纳米数据世界杯数据接口,中超数据,体育数据比分,世界杯赛程api,足球比赛实时数据接口
Data-driven anomaly detection and early warning of item C in the May 1st mathematical modeling competition in 2021
[wechat applet full stack development course] course directory (mpvue+koa2+mysql)
Fcpx quickly add subtitles | Final Cut Pro import fcpxml subtitle file does not match the video time? I got it in code
独步武林,架构选型手册(包含 PDF)
Study on correlation of pumpkin price and design of price prediction model based on BP neural network
微服务调用组件Ribbon底层调用流程分析
[zufe expense reimbursement] zhecai invoice reimbursement specification (taking Xinmiao reimbursement as an example), which can be passed in one trip at most
随机推荐
Online notes on Mathematics for postgraduate entrance examination (8): Kego equations, eigenvalues and eigenvectors, similarity matrix, quadratic series courses
Title B of the certification cup of the pistar cluster in the Ibagu catalog
匯付國際為跨境電商賦能:做合規的跨境支付平臺!
Flutter multilingual intl: ^0.17.0 cannot be imported
Data-driven anomaly detection and early warning of 21 May Day C
pmp考试题型需要注意哪些?
MySQL创建给出语句
[2020 cloud development + source code] 30 minutes to create and launch wechat applet practical project | zero cost | cloud database | cloud function
How much money have I made by sticking to fixed investment for 3 years?
[zufe school competition] difficulty classification and competition suggestions of common competitions in the school (taking Zhejiang University of Finance and economics as an example)
Match a mobile number from a large number of mobile numbers
[buuctf.reverse] 117-120
Is it safe to open an account online? Who can I ask?
Abbreviations of common English terms for IC R & D
Reza RA series - development environment construction
Flitter gets the height of the top status bar
Voiceprint Technology (IV): Engineering deployment of voiceprint recognition
js工具函数,自己封装一个节流函数
Is the client that gets the scanning code wechat or Alipay
Is it safe to open an account in a mobile phone or a securities company?