教师工资管理系统Java代码
时间: 2023-06-22 11:42:47 浏览: 77
以下是一个简单的教师工资管理系统的Java代码示例,仅供参考:
前端代码(使用Java Swing):
```
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class App {
private JFrame frame;
private JLabel label;
private JButton button;
public App() {
frame = new JFrame("教师工资管理系统");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);
frame.setLayout(null);
label = new JLabel("欢迎使用教师工资管理系统");
label.setBounds(50, 50, 200, 20);
frame.add(label);
button = new JButton("查询工资");
button.setBounds(100, 100, 100, 30);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// 调用后端API查询工资
int salary = API.querySalary();
// 显示查询结果
JOptionPane.showMessageDialog(frame, "您的工资为:" + salary + "元");
}
});
frame.add(button);
frame.setVisible(true);
}
public static void main(String[] args) {
new App();
}
}
```
后端代码(使用Java Spring Boot):
```
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@SpringBootApplication
@RestController
public class API {
@GetMapping("/api/query_salary")
public static int querySalary(@RequestParam int id) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int salary = 0;
try {
// 连接数据库,查询工资
conn = DriverManager.getConnection("jdbc:sqlite:salary.db");
pstmt = conn.prepareStatement("SELECT salary FROM teacher WHERE id = ?");
pstmt.setInt(1, id);
rs = pstmt.executeQuery();
if (rs.next()) {
salary = rs.getInt("salary");
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (rs != null) rs.close();
if (pstmt != null) pstmt.close();
if (conn != null) conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
// 返回查询结果
return salary;
}
public static void main(String[] args) {
SpringApplication.run(API.class, args);
}
}
```
以上代码仅为示例,实际的教师工资管理系统可能需要更多的功能和模块,具体的实现方式也会因为技术选型和需求而有所不同。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)