新增对UserInfo的支持,修改了users表,fakeUser,用于支持index的渲染的getUserInfo
This commit is contained in:
parent
660904629f
commit
f063c5056d
@ -64,7 +64,14 @@ public class DatabaseService {
|
||||
String createUsersTable = "CREATE TABLE users (" +
|
||||
"id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, " +
|
||||
"username VARCHAR(255) UNIQUE, " +
|
||||
"password VARCHAR(255))";
|
||||
"name VARCHAR(255), " +
|
||||
"password VARCHAR(255), " +
|
||||
"introduction CLOB, " +
|
||||
"interests CLOB, " +
|
||||
"experiences CLOB, " +
|
||||
"skills CLOB, " +
|
||||
"careerGoals CLOB, " +
|
||||
"projects CLOB)";
|
||||
|
||||
String createProjectsTable = "CREATE TABLE projects (" +
|
||||
"id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, " +
|
||||
@ -141,6 +148,46 @@ public class DatabaseService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 更新用户信息的方法
|
||||
public void updateUserInfo(String username, UserInfo userInfo) throws SQLException {
|
||||
String sql = "UPDATE users SET introduction = ?, interests = ?, experiences = ?, skills = ?, careerGoals = ?, name = ? WHERE username = ?";
|
||||
try (Connection conn = getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
|
||||
stmt.setString(1, userInfo.getIntroduction());
|
||||
stmt.setString(2, userInfo.getInterests());
|
||||
stmt.setString(3, userInfo.getExperiences());
|
||||
stmt.setString(4, userInfo.getSkills());
|
||||
stmt.setString(5, userInfo.getCareerGoals());
|
||||
stmt.setString(6, userInfo.getName());
|
||||
stmt.setString(7, username);
|
||||
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public UserInfo getUserInfo(String username) throws SQLException {
|
||||
String sql = "SELECT * FROM users WHERE username = ?";
|
||||
try (Connection conn = getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setString(1, username);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
return new UserInfo(
|
||||
rs.getString("username"),
|
||||
rs.getString("introduction"),
|
||||
rs.getString("interests"),
|
||||
rs.getString("experiences"),
|
||||
rs.getString("skills"),
|
||||
rs.getString("careerGoals"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void saveProjects(String username, List<Project> projects) throws SQLException {
|
||||
try (Connection conn = getConnection()) {
|
||||
for (Project project : projects) {
|
||||
@ -189,6 +236,16 @@ public class DatabaseService {
|
||||
public void loadFakeUsers() throws SQLException {
|
||||
registerUser("admin", "admin");
|
||||
registerUser("user", "user");
|
||||
UserInfo userInfo = new UserInfo(
|
||||
"Ryan Goodwill",
|
||||
"Hello! I'm Ryan Goodwill, a passionate programmer. I'm interested in various AI models and their applications, Raspberry Pi projects, playing the piano, playing tennis, and cycling.",
|
||||
"Pascal, C++, Python, Java, Django, Raspberry Pi projects, AI model experimentation, sensor integration, control systems, web development, remote hardware control, video streaming, communication protocols.",
|
||||
"Elementary school programming with Pascal -> Learned C++ and Python -> University projects in Java (Cloud Factory Management System, Android Weather Forecast App) -> Raspberry Pi projects (infrared communication protocol, plant care box with sensors, control webpage) -> Deployed and tested Large Language Models and AI voice synthesis -> Ongoing project: video downloading, OCR, ASR, SVG conversion, LLM querying.",
|
||||
"Python, C++, Java, Pascal, Django, Raspberry Pi, AI models, Sensors, Control Systems, Web Development, Remote Hardware Control, Video Streaming, Communication Protocol Development.",
|
||||
"To work in an internet company for a few years before starting my own business."
|
||||
);
|
||||
updateUserInfo("admin", userInfo);
|
||||
updateUserInfo("user", userInfo);
|
||||
}
|
||||
|
||||
public void loadAndSaveFakeProjects() throws SQLException {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user