当前位置:网站首页>Summary of development issues
Summary of development issues
2022-07-03 12:10:00 【Dull Yanan】
Summary of development issues
Time format problem
Database Date Format and front-end interface Date The format is different , You can use annotations for conversion , Or use SpringMVC Type converter in
bean The code is as follows
@DateTimeFormat(pattern ="yyyy-MM-dd HH:mm:SS")
private Date birth;
The front-end code is as follows
<input name="birth" type="text" class="form-control" placeholder="2000-0-2" th:value="${emp!=null}?${#dates.format(emp.birth, 'yyyy-MM-dd HH:mm')}">
The trouble is SpringMVC Custom type conversion of
public class StringToDateConverter implements Converter<String, Date> {
@Override
public Date convert(String source) {
DateFormat format = null;
try {
if(StringUtils.isEmpty(source)) {
throw new NullPointerException(" Please enter the date to convert ");
}
format = new SimpleDateFormat("yyyy-MM-dd");
Date date = format.parse(source);
return date;
} catch (Exception e) {
throw new RuntimeException(" Wrong input date ");
}
}
}
<!-- Configure custom type converter -->
<bean class="org.springframework.context.support.ConversionServiceFactoryBean" id="conversionServiceFactoryBean">
<property name="converters" >
<set>
<bean class="cn.itheima.utils.StringToDateConverter"/>
</set>
</property>
</bean>
Log output level setting
Sometimes it's annoying , There are a lot of logs , There are few useful sentences , How to modify the log is as follows
Global settings
propertises
logging.level.root=WARN
YML
logging:
level:
root: DEBUG
`
Specific packages
properties To configure
logging.level. Your bag name . Your bag name . Your bag name =DEBUG
For example, your package name is com.heima, It's going to be written as
logging.level.com.heima=DEBUG
yaml To configure
logging:
level:
com:
heima: DEBUG
thymeleaf Introduce resource issues
SpringBoot2 Standard construction .springboot2 You need to configure the static resource path
static and templates Automatic production
Configure static resource scanning
@Configuration
public class ToknanConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// Route /static/** Mapping to /static The files under the
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
}
}
Introduction mode
<script type="text/javascript" src="../static/js/jquery.parallax-scroll.js" th:href="@{/js/jquery.parallax-scroll.js}"></script>
<script type="text/javascript" src="../static/js/show.js" th:href="@{/js/show.js}"></script>
<script type="text/javascript" src="../static/js/jquery.dialogBox.js" th:href="@{/js/jquery.dialogBox.js}"></script>
<script type="text/javascript" src="../static/js/login.js" th:href="@{/js/login.js}"></script>
<link rel="stylesheet" type="text/css" href="../static/css/font-awesome.min.css" th:href="@{/css/font-awesome.min.css}">
<link rel="stylesheet" type="text/css" href="../static/css/swipebox.css" th:href="@{/css/swipebox.css}">
<link rel="stylesheet" type="text/css" href="../static/css/jquery.dialogbox.css" th:href="@{/css/jquery.dialogbox.css}">
<link rel="stylesheet" type="text/css" href="../static/css/show.css" th:href="@{/css/show.css}">
Boot2 Resource interception problem
SpringBoot2 It will automatically intercept all resources , You need to configure which resources can be accessed through ,
It doesn't solve the problem of image access , So put it on the server
@Resource
private HandlerInterceptor handlerInterceptor;
// Register interceptors , Release resources
@Override
public void addInterceptors(InterceptorRegistry registry) {
WebMvcConfigurer.super.addInterceptors(registry);
registry.addInterceptor(handlerInterceptor)
.addPathPatterns("/**")
.excludePathPatterns("/images/**")
.excludePathPatterns("/css/*")
.excludePathPatterns("/js/**");
}
LomBok
@Data
One of the most commonly used annotations . Annotation on class , Provide all properties of this class getter/setter Method , It also provides equals、canEqual、hashCode、toString Method .
@AllArgsConstructor
Act on a class , Provide a constructor for this class that contains all parameters , Note that the default constructor does not provide .
@NoArgsConstructor
Act on a class , Provides a construction method without parameters . You can talk to @AllArgsConstructor Use at the same time , Two construction methods are generated : Nonparametric construction method and total parameter construction method .
Log4J How to write it
log4j.rootLogger=debug, stdout, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=example.log
log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=5
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.21</version>
</dependency>
Local test run vue
1. Installation services :
npm install serve -g
2. Get into dist file
cd dist
3. Operation service
serve
visit
http://192.168.1.8:3000/
Required request body is missing error
because Get The way of requesting to send data is not json Format , So when we use @RequsetBody encapsulation Get When requested data, data cannot be obtained , take @RequsetBody Remove the comment , Data can also be enclosed into objects
@GetMapping("findAllByPageInterface")
public @ResponseBody ApiResponse findAllByPage(findStockOutReq stockOutReq) {
// Judge whether the obtained page is empty
if(stockOutReq.getLimit() <= 0) {
stockOutReq.setLimit(10);
}
A processor in the background , The front end should also set the corresponding interface
// As springmvc Exception handler
@RestControllerAdvice
public class ProjectExceptionAdvice {
/**
* Intercept all exception information
*/
@ExceptionHandler(Exception.class)
public R doException(Exception ex){
// Log
// Inform operation and maintenance
// Notification development
ex.printStackTrace();
return new R(" Server failure , Please try again later !");
}
}
边栏推荐
- Go语言实现静态服务器
- Solutions to the failure of installing electron
- Dart: about Libraries
- 牛牛的组队竞赛
- STL tutorial 8-map
- MySQL uses the method of updating linked tables with update
- DEJA_ Vu3d - 054 of cesium feature set - simulate the whole process of rocket launch
- PHP导出word方法(一phpword)
- Shutter: about inheritedwidget
- SystemVerilog -- OOP -- copy of object
猜你喜欢
Raven2 of vulnhub
Groovy测试类 和 Junit测试
Is BigDecimal safe to calculate the amount? Look at these five pits~~
vulnhub之cereal
vulnhub之Nagini
PHP export word method (phpword)
(database authorization - redis) summary of unauthorized access vulnerabilities in redis
shardingSphere分库分表<3>
Pki/ca and digital certificate
为什么我的mysql容器启动不了呢
随机推荐
[combinatorics] permutation and combination (summary of permutation and combination content | selection problem | set permutation | set combination)
ArcGIS应用(二十一)Arcmap删除图层指定要素的方法
DEJA_VU3D - Cesium功能集 之 053-地下模式效果
DNS multi-point deployment IP anycast+bgp actual combat analysis
Redis notes 01: Introduction
Develop plug-ins for idea
vulnhub之Ripper
Simple factory and factory method mode
Groovy test class and JUnit test
Notes on 32-96 questions of sword finger offer
STL tutorial 10 container commonalities and usage scenarios
MCDF Experiment 1
AOSP ~ NTP (Network Time Protocol)
Qt OpenGL 纹理贴图
4000字超详解指针
SLF4J 日志门面
vulnhub之raven2
(database authorization - redis) summary of unauthorized access vulnerabilities in redis
Unicode encoding table download
Xiaopeng P7 hit the guardrail and the airbag did not pop up. The official responded that the impact strength did not meet the ejection requirements