class StudentList extends React.Component {
constructor(props) {
super(props);
this.state = { students: [] };
}
componentDidMount() {
fetch('/api/students')
.then(response => response.json())
.then(data => this.setState({ students: data }));
}
render() {
return (
学生列表
{this.state.students.map(student => (
))}
);
}
}
const express = require('express');
const app = express();
const mysql = require('mysql');
const db = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'password',
database: 'school_db'
});
app.get('/api/students', (req, res) => {
db.query('SELECT * FROM students', (err, results) => {
if (err) throw err;
res.send(results);
});
});
app.listen(3001, () => console.log('Server running on port 3001'));
本站部分内容及素材来源于互联网,由AI智能生成,如有侵权或言论不当,联系必删!