当前位置:网站首页>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

边栏推荐
- Chisel tutorial - 06 Phased summary: implement an FIR filter (chisel implements 4-bit FIR filter and parameterized FIR filter)
- Add control at the top of compose lazycolumn
- 多媒体NFT聚合平台OKALEIDO即将上线,全新的NFT时代或将来临
- Record: MySQL changes the time zone
- [combinatorics] dislocation problem (recursive formula | general term formula | derivation process)*
- Unity webgl optimization
- [Yu Yue education] world reference materials of Microbiology in Shanghai Jiaotong University
- NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
- Recent learning experience
- 204. Count prime
猜你喜欢

Ping problem between virtual machine and development board

Kratos微服务框架下实现CQRS架构模式

Opencv learning notes (continuously updated)

Analysis of the reasons why enterprises build their own software development teams to use software manpower outsourcing services at the same time

Does SQL always report foreign key errors when creating tables?

Zhengda futures news: soaring oil prices may continue to push up global inflation

leetcode:11. 盛最多水的容器【双指针 + 贪心 + 去除最短板】

Add control at the top of compose lazycolumn

CV in transformer learning notes (continuously updated)

Install apache+php+mysql+phpmyadmin xampp and its error resolution
随机推荐
Mysql45 lecture learning notes (II)
Torch learning notes (7) -- take lenet as an example for dataload operation (detailed explanation + reserve knowledge supplement)
Install apache+php+mysql+phpmyadmin xampp and its error resolution
Data analysis is popular on the Internet, and the full version of "Introduction to data science" is free to download
leetcode:556. Next larger element III [simulation + change as little as possible]
High concurrency Architecture - distributed search engine (ES)
What problems can cross-border e-commerce sellers solve with multi platform ERP management system
235. Ancêtre public le plus proche de l'arbre de recherche binaire [modèle LCA + même chemin de recherche]
flask 生成swagger文档
Multifunctional web file manager filestash
Gao Qing, Beijing University of Aeronautics and Astronautics: CIM is a natural quantum computing platform for graph data processing
22.2.14 -- station B login with code -for circular list form - 'no attribute' - 'needs to be in path selenium screenshot deviation -crop clipping error -bytesio(), etc
Boost.Asio Library
2022.02.11
Hard disk monitoring and analysis tool: smartctl
Coordinate layer conversion tool (video)
Real time split network (continuous update)
Suffix derivation based on query object fields
Chisel tutorial - 06 Phased summary: implement an FIR filter (chisel implements 4-bit FIR filter and parameterized FIR filter)
Recommend a simple browser tab
