刚刚接触了ssh框架,对于set方法的参数赋值有点搞不懂,想请教一下大家 这个是service层,对于里面 Admin checkLogin(String username,String password,String ip) throws Exception; username和password还有ip是如何来获取值的 package service; import vo.Admin; public interface AdminService extends CommonService<Admin> { boolean isUsernameExist(String username); Admin checkLogin(String username,String password,String ip) throws Exception; } |
|
13分 |
一般你调用这个方法的时候,就已经获取到了username和ip的值,
调用的时候直接传给它 |
13分 |
页面提交数据会把相应数据传递到后台,后台要有接收的变量名,然后传递到方法里就可以了
|
14分 |
代码:
//bean public class UserEntity { String username; String password; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } //action public class UserAction extends ActionSupport implements ServletRequestAware, ServletResponseAware{ private UserEntity userEntity; @Autowired private AdminService adminService ; protected HttpServletRequest request; public String login(){ adminService(userEntity.getUsername() ,userEntity.getPassword(),getIpAddr(request)) ; } public UserEntity getUserEntity() { return userEntity; } public void setUserEntity(UserEntity userEntity) { this.userEntity = userEntity; } public static String getIpAddr(HttpServletRequest request) { String ip = request.getHeader("x-forwarded-for"); if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } return ip; } } //jsp: <form> <input name="userEntity.userName"/> <input name="userEntity.password"/> </form> //说明:主要使用方法如上,但已经足够说明传值的方式了 |
ok谢谢啦!
|