12.12
后端代码
UserController
package com.example.controller; import com.example.pojo.*; import com.example.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/user") public class UserController { @Autowired private UserService userService; //登陆验证 @GetMapping("/getByUser") public Result getByUser(String username, String password) { return Result.success(userService.getByUser(username, password)); } @PostMapping("/add") public Result add(@RequestBody Customer customer) { userService.add(customer); return Result.success(customer); } @GetMapping("/getAll") public Result getAll() { return Result.success(userService.getAll()); } @GetMapping("/selectid/{id}") public Result selectid(@PathVariable("id") String id) { return Result.success(userService.selectid(id)); } @PutMapping("/updateById/{id}/{state}") public Result updateById(@PathVariable("id") String id, @PathVariable("state") String state) { userService.updateById(id, state); return Result.success(userService.selectid(id)); } @PostMapping("/addUser") public Result addUser(@RequestBody Users users) { userService.addUser(users); return Result.success(users); } @PostMapping("/addHouse") public Result addHouse(@RequestBody House house) { userService.addHouse(house); return Result.success(house); } @PostMapping("/addAgent") public Result addAgent(@RequestBody Agent agent) { userService.addAgent(agent); return Result.success(agent); } @GetMapping("/selectUsers/{username}") public Result selectUsers(@PathVariable("username") String id) { return Result.success(userService.selectUsers(id)); } @GetMapping("/select1/{id}") public Result select1(@PathVariable("id") String id) { return Result.success(userService.select1(id)); } @GetMapping("/select2/{id}") public Result select2(@PathVariable("id") String id) { return Result.success(userService.select2(id)); } @PutMapping("/updatePassword/{id}/{password}") public Result updatePassword(@PathVariable("id") String id, @PathVariable("password") String password) { userService.updatePassword(id, password); return Result.success(userService.selectUsers(id)); } @GetMapping("/selectHouse") public Result selectHouse() { return Result.success(userService.selectHouse()); } @GetMapping("/selectHouse2/{type}") public Result selectHouse2(String type) { return Result.success(userService.selectHouse2(type)); } @GetMapping("/selectHouse3/{username}") public Result selectHouse3(String username) { return Result.success(userService.selectHouse3(username)); } }
UserService
package com.example.service; import com.example.mapper.UserMapper; import com.example.pojo.Agent; import com.example.pojo.Customer; import com.example.pojo.House; import com.example.pojo.Users; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; import java.util.Random; @Service public class UserService { @Autowired private UserMapper userMapper; //登陆验证 public Users getByUser(String username, String password) { return userMapper.getByUser(username, password); } public void add(Customer customer) { String id = customer.getId(); String name = customer.getName(); String sex = customer.getSex(); String phone = customer.getPhone(); String idNumber = customer.getIdNumber(); String position = customer.getPosition(); int state = customer.getState(); userMapper.add(id, name, sex, phone, idNumber, position, state); } public List<Customer> getAll() { int state = 0; return userMapper.getAll(state); } public Customer selectid(String id) { return userMapper.selectid(id); } public void updateById(String id, String state) { userMapper.updateById(id, state); } public void addUser(Users users) { String id = users.getId(); String password = users.getPassword(); String position = users.getPosition(); userMapper.addUser(id, password, position); } public void addHouse(House house) { String id = house.getId(); String type = house.getType(); String position = house.getPosition(); String year = house.getYear(); String area = house.getArea(); String much = house.getMuch(); String state = house.getState(); userMapper.addHouse(id, type, position, year, area, much, state); } public void addAgent(Agent agent) { String id = agent.getAgentID(); String name = agent.getAgentName(); String address = agent.getAgentAddress(); String phone = agent.getPhone(); userMapper.addAgent(id, name, address, phone); } public Users selectUsers(String id) { return userMapper.selectUsers(id); } public Agent select1(String id) { return userMapper.select1(id); } public Customer select2(String id) { return userMapper.select2(id); } public void updatePassword(String id, String password) { userMapper.updatePassword(id, password); } public List<House> selectHouse() { return userMapper.selectHouse(); } public List<House> selectHouse2(String type) { return userMapper.selectHouse2(type); } public List<House> selectHouse3(String username) { return userMapper.selectHouse3(username); } }