当前位置:网站首页>SSM integration - joint debugging of front and rear protocols (list function, add function, add function status processing, modify function, delete function)
SSM integration - joint debugging of front and rear protocols (list function, add function, add function status processing, modify function, delete function)
2022-07-03 18:50:00 【Xia Zhi 121】
Catalog
3、 ... and 、 Add function status processing
One 、 List function
SpringMVC Set to block all paths , It also intercepts the request of the page , If you visit the page , I can't find , can't make a good living SpringMVC, So we need to add a new configuration class , Release resources .
SpringMvcSupport Configuration class
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
@Configuration
public class SpringMvcSupport extends WebMvcConfigurationSupport {
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/pages/**").addResourceLocations("/pages/");
registry.addResourceHandler("/css/**").addResourceLocations("/css/");
registry.addResourceHandler("/js/**").addResourceLocations("/js/");
registry.addResourceHandler("/plugins/**").addResourceLocations("/plugins/");
}
}After writing the configuration , Must let SpringMVC Load on , stay @ComponentScan Loading .
@Configuration
@ComponentScan({"com.itheima.controller","com.itheima.config"})
@EnableWebMvc
public class SpringMvcConfig {
}send out ajax request , Get the return value , Let the current data model load the data transferred from the background
books.html
// list
getAll() {
// send out ajax request
axios.get("/books").then((res)=>{
this.dataList = res.data.data;
});
},Page list display effect

Two 、 Add functionality
Pop up add window function
// Pop up add window
handleCreate() {
this.dialogFormVisible = true;
this.resetForm();
},Add functionality
// add to
handleAdd () {
// send out ajax request
axios.post("/books",this.formData).then((res)=>{
// If the operation is successful , Close the bomb layer , Display the data
this.dialogFormVisible = false;
this.getAll();
});
},Add functional effects

Effect after adding successfully
3、 ... and 、 Add function status processing
Add function status processing to , If there is any abnormality, the status will be displayed , No abnormal success .
// add to
handleAdd () {
// send out ajax request
axios.post("/books",this.formData).then((res)=>{
console.log(res.data);
// If the operation is successful , Close the bomb layer , Display the data
if(res.data.code == 20011){
this.dialogFormVisible = false;
this.$message.success(" Add success ");
}else if(res.data.code == 20010){
this.$message.error(" Add failure ");
}else{
this.$message.error(res.data.msg);
}
}).finally(()=>{
this.getAll();
});
},Add successful effect

stay BookServiceImpl The number of affected rows added to is greater than 0, The number of rows affected is greater than 0 It's true , be equal to 0 For false
public boolean save(Book book) {
return bookDao.save(book) > 0;
}
public boolean update(Book book) {
return bookDao.update(book) > 0;
}
public boolean delete(Integer id) {
return bookDao.delete(id) > 0;
}When adding, the input is greater than the maximum length of the field required by the data table 20, Can get the effect of failure


Because of the two-way binding , So it will echo , Reset the form , Add a function to call in the pop-up .
// Reset form
resetForm() {
this.formData = {};
},Four 、 Modify the function
The edit window pops up , according to id Inquire about , Show the bomb layer , Load data .
// The edit window pops up
handleUpdate(row) {
// Query data , according to id Inquire about
axios.get("/books/"+row.id).then((res)=>{
if(res.data.code == 20041){
// Display bomb layer , Load data
this.formData = res.data.data;
this.dialogFormVisible4Edit = true;
}else{
this.$message.error(res.data.msg);
}
});
},Edit window effect

Editing function is similar to adding function , modify put Request and modify the corresponding status code and corresponding prompt information .
// edit
handleEdit() {
// send out ajax request
axios.put("/books",this.formData).then((res)=>{
// If the operation is successful , Close the bomb layer , Display the data
if(res.data.code == 20031){
this.dialogFormVisible4Edit = false;
this.$message.success(" Modification successful ");
}else if(res.data.code == 20030){
this.$message.error(" Modification failed ");
}else{
this.$message.error(res.data.msg);
}
}).finally(()=>{
this.getAll();
});
},Successfully modified function effect


Failed to modify the function effect


5、 ... and 、 Delete function
Pop up the prompt box , Prompt operation , according to id To delete , You can also cancel the deletion prompt .
// Delete
handleDelete(row) {
//1. Pop up the prompt box
this.$confirm(" This operation permanently deletes the current data , Whether or not to continue ?"," Tips ",{
type:'info'
}).then(()=>{
//2. Do delete business
axios.delete("/books/"+row.id).then((res)=>{
if(res.data.code == 20021){
this.$message.success(" Delete successful ");
}else{
this.$message.error(" Delete failed ");
}
}).finally(()=>{
this.getAll();
});
}).catch(()=>{
//3. Cancel deletion
this.$message.info(" Cancel the delete operation ");
});
}Delete the prompt box effect

Delete successful effect

Delete the cancellation effect

边栏推荐
- SQL custom collation
- JS_ Array_ sort
- Raft 日志复制
- C enum contains value - C enum contains value
- Xception for deeplab v3+ (including super detailed code comments and original drawing of the paper)
- Sepconv (separable revolution) code recurrence
- 204. Count prime
- Dynamic planning -- expansion topics
- High concurrency Architecture - read write separation
- Processing of user input parameters in shell script
猜你喜欢

User identity used by startup script and login script in group policy

After the festival, a large number of people change careers. Is it still time to be 30? Listen to the experience of the past people

2022-2028 global physiotherapy clinic industry research and trend analysis report
![235. The nearest common ancestor of the binary search tree [LCA template + same search path]](/img/f5/f2d244e7f19e9ddeebf070a1d06dce.png)
235. The nearest common ancestor of the binary search tree [LCA template + same search path]

MySQL duplicate check

2022-2028 global marking ink industry research and trend analysis report

Torch learning notes (7) -- take lenet as an example for dataload operation (detailed explanation + reserve knowledge supplement)

Getting started with JDBC

Okaleido, a multimedia NFT aggregation platform, is about to go online, and a new NFT era may come

Analysis of the reasons why enterprises build their own software development teams to use software manpower outsourcing services at the same time
随机推荐
High concurrency architecture cache
Caddy server agent
flask 生成swagger文档
There are several levels of personal income tax
平淡的生活里除了有扎破皮肤的刺,还有那些原本让你魂牵梦绕的诗与远方
How does GCN use large convolution instead of small convolution? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)
What is the function of registering DLLs- What does registering a DLL do?
[combinatorics] dislocation problem (recursive formula | general term formula | derivation process)*
Know what it is, and know why, JS object creation and inheritance [summary and sorting]
[combinatorics] exponential generating function (properties of exponential generating function | exponential generating function solving multiple set arrangement)
Implementation of cqrs architecture mode under Kratos microservice framework
[Godot] add menu button
达梦数据库的物理备份和还原简解
Failed to start component [StandardEngine[Catalina]. StandardHost[localhost]. StandardContext
2022.02.11
SSH 远程执行命令简介
Ping problem between virtual machine and development board
The online customer service system developed by PHP is fully open source without encryption, and supports wechat customer service docking
FBI 警告:有人利用 AI 换脸冒充他人身份进行远程面试
“google is not defined” when using Google Maps V3 in Firefox remotely
