ssm搭建 (3)

在dao中新建UserDao

@Repository public interface UserDao { @Select("SELECT password FROM user WHERE name = #{name}") String getUserByNameAndPassword(@Param("name") String name, @Param("password") String password); }

service包中用来存放接口
在service下新建包serviceimpl,该包下存放service包中接口的实现类
service中新建接口类UserService

public interface UserService { boolean loginUserStatus(String name,String password); }

在serviceimpl包下新建UserServiceImpl类实现UserService接口

@Service public class UserServiceImpl implements UserService { @Autowired private UserDao userDao; public boolean loginUserStatus(String name, String password) { if(name == null || "".equals(name)){ return false; } if(password == null || "".equals(password)){ return false; } String passwordByName = userDao.getPasswordByName(name); System.out.println("passwordByName = " + passwordByName); if (password == null){ return false; } if (password.equals(passwordByName)) { return true; } return false; } }

controller下新建类UserController

@Controller @RequestMapping("user") public class UserController { @Autowired private UserService userService; @PostMapping("userLogin") public String userLogin(String name,String password){ if (userService.loginUserStatus(name,password)) { return "/loginsuccess.html"; } return "/loginfailed.html"; } }

在index.html的form表单的action中写入
/userLogin/userLogin.php
写入form表单中的数据将会提交到这个controller中

运行,tomcat自行配置,记得将war配置到tomcat中,以及pom中packing war

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zyyzyy.html