基于jfinal+element ui+vue的项目示例代码
时间: 2023-07-25 11:11:06 浏览: 143
jfinal 项目例子
5星 · 资源好评率100%
以下是一个基于jfinal+element ui+vue的简单示例代码:
后端JFinal代码:
```
public class UserController extends Controller {
public void index() {
render("index.html");
}
public void getUsers() {
List<User> userList = UserService.getAllUsers();
renderJson(userList);
}
public void addUser() {
User user = getModel(User.class);
boolean result = UserService.addUser(user);
renderJson(result);
}
public void deleteUser() {
int id = getParaToInt("id");
boolean result = UserService.deleteUser(id);
renderJson(result);
}
}
```
前端Vue代码:
```
<template>
<div>
<el-button type="primary" @click="addUser">Add User</el-button>
<el-table :data="userList">
<el-table-column prop="id" label="ID"></el-table-column>
<el-table-column prop="name" label="Name"></el-table-column>
<el-table-column prop="age" label="Age"></el-table-column>
<el-table-column label="Operation">
<template slot-scope="scope">
<el-button type="danger" @click="deleteUser(scope.row.id)">Delete</el-button>
</template>
</el-table-column>
</el-table>
</div>
</template>
<script>
import axios from 'axios'
export default {
name: 'User',
data() {
return {
userList: []
}
},
mounted() {
this.getUsers()
},
methods: {
getUsers() {
axios.get('/user/getUsers').then(response => {
this.userList = response.data
})
},
addUser() {
axios.post('/user/addUser', {
name: 'John',
age: 25
}).then(response => {
if (response.data) {
this.getUsers()
}
})
},
deleteUser(id) {
axios.delete(`/user/deleteUser?id=${id}`).then(response => {
if (response.data) {
this.getUsers()
}
})
}
}
}
</script>
```
以上示例代码仅供参考,具体实现方式可以根据自己的需求进行调整。
阅读全文