Skip to content
Snippets Groups Projects

analyse result save

Merged Peiyi Liu requested to merge Imagerisk into main
6 unresolved threads
12 files
+ 409
14
Compare changes
  • Side-by-side
  • Inline
Files
12
@@ -77,13 +77,26 @@ public class UserController {
@@ -77,13 +77,26 @@ public class UserController {
}
}
@GetMapping("/user/{id}")
/*@GetMapping("/user/{id}")
public String getUser(@PathVariable("id") int id, Model model) {
public String getUser(@PathVariable("id") int id, Model model) {
User user = jdbcTemplate.queryForObject("SELECT u.*, IFNULL(AVG(r.rating), 0) AS average_rating FROM users u LEFT JOIN ratings r ON u.id = r.user_id WHERE u.id = ?", new Object[]{id}, new UserRowMapper());
User user = jdbcTemplate.queryForObject("SELECT u.*, IFNULL(AVG(r.rating), 0) AS average_rating FROM users u LEFT JOIN ratings r ON u.id = r.user_id WHERE u.id = ?", new Object[]{id}, new UserRowMapper());
model.addAttribute("user", user);
model.addAttribute("user", user);
return "user";
return "user";
 
}*/
 
 
@GetMapping("/user/{id}")
 
public String getUser(@PathVariable("id") int id, Model model) {
 
// 通过SQL查询获取用户信息、手动评分平均值以及图像分析结果
 
User user = jdbcTemplate.queryForObject(
 
"SELECT u.*, IFNULL(AVG(r.rating), 0) AS average_rating, u.score, u.risk_level " +
 
"FROM users u LEFT JOIN ratings r ON u.id = r.user_id WHERE u.id = ?",
 
new Object[]{id}, new UserRowMapper());
 
 
model.addAttribute("user", user);
 
return "user";
}
}
    • Overall, this code implements a functionality to retrieve specific user information, including the user's basic details, average rating, and image analysis result. This information is then passed to the view for display on the user interface. This functionality could be part of a user profile or detailed information page.

Please register or sign in to reply
 
@PostMapping("/rateUser")
@PostMapping("/rateUser")
public String rateUser(@RequestParam("userId") int userId, @RequestParam("rating") int rating) {
public String rateUser(@RequestParam("userId") int userId, @RequestParam("rating") int rating) {
jdbcTemplate.update("INSERT INTO ratings (user_id, rating) VALUES (?, ?)", userId, rating);
jdbcTemplate.update("INSERT INTO ratings (user_id, rating) VALUES (?, ?)", userId, rating);
@@ -103,6 +116,9 @@ public class UserController {
@@ -103,6 +116,9 @@ public class UserController {
user.setJobTitle(rs.getString("job_title"));
user.setJobTitle(rs.getString("job_title"));
user.setCallHistory(rs.getString("call_history"));
user.setCallHistory(rs.getString("call_history"));
user.setAverageRating(rs.getFloat("average_rating")); // 确保查询结果中包含该字段
user.setAverageRating(rs.getFloat("average_rating")); // 确保查询结果中包含该字段
 
user.setScore(rs.getFloat("score"));
 
String riskLevel = rs.getString("risk_level");
 
user.setRiskLevel(riskLevel);
return user;
return user;
}
}
    • In summary, the first part of the code handles the functionality to rate a user by inserting a new rating record into the ratings table. The second part of the code is a custom UserRowMapper implementation that maps the result set of a database query to a User object, including various user-related properties such as job title, call history, average rating, score, and risk level.

Please register or sign in to reply
}
}
Loading