springboot实战项目之用户注册功能实现
1、在控制器里面写控制程序(控制器调用的是service业务层的接口)
@Controller @RequestMapping("user") public class UserController{ @Autowired private UserService userService; //开发用户注册 @PostMapping("register") public String register(User user,String code,HttpSession session){ //1、判断验证码是否通过 if(session.getAttribute("code").toString().equalsIgnoreCase(code)){ //2、通过之后注册 userService.save(user); return "redirect:/ems/login.jsp"; }else { return "redirect:/ems/register.jsp"; } //3、用户验证码不通过,直接返回登录页面 }
2、service业务层实现(业务层调用dao层)
public interface UserService { void save(User user); }
//UserService
@Service @Transactional public class UserServiceImpl implements UserService { @Autowired private UserDAO userDAO; @Override public void save(User user) { user.setId(UUID.randomUUID().toString()); userDAO.save(user); } }
//UserServiceImpl
结构层次:
along