login.do测试,500 空指针异常,参数没传过来??
来源:6-9 用户模块所有功能自测试
筱爻
2017-08-17
获取不到参数,参数没传过来,什么问题??
难道 Restlet client 这个插件需要什么配置,才能传参成功的吗?
UserController.java
package com.mall.controller.protal; import com.mall.common.Const; import com.mall.common.ResponseCode; import com.mall.common.ServerResponse; import com.mall.pojo.User; import com.mall.service.IUserService; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpSession; @Controller @RequestMapping("/user/") public class UserController { private IUserService iUserService; /** * 用户登录 * @param username * @param password * @param session * @return * 如果登录成功存进session里面 */ @RequestMapping(value="login.do", method = RequestMethod.POST) @ResponseBody public ServerResponse<User> login(String username,String password, HttpSession session){ ServerResponse<User> response = iUserService.login(username, password); System.out.println("------Controller返回username=---------"+username); if(response.isSuccess()){ session.setAttribute(Const.CURRENT_USER,response.getData()); } return response; } /** * 退出登录 * @param session * @return */ @RequestMapping(value="logout.do", method = RequestMethod.POST) @ResponseBody public ServerResponse<User> logout(HttpSession session){ session.removeAttribute(Const.CURRENT_USER); return ServerResponse.createBySuccess(); } /** * 用户注册 * @param user * @return */ @RequestMapping(value="register.do", method = RequestMethod.POST) @ResponseBody public ServerResponse<String> register(User user){ return iUserService.register(user); } //校验用户名和email是否存在 @RequestMapping(value="check_valid.do", method = RequestMethod.POST) @ResponseBody public ServerResponse<String> checkValid(String str , String type){ return iUserService.checkValid(str,type); } //获取用户登录信息 @RequestMapping(value="get_user_info.do", method = RequestMethod.POST) @ResponseBody public ServerResponse<User> getUserInfo(HttpSession session){ User user = (User) session.getAttribute(Const.CURRENT_USER); if(user != null){ return ServerResponse.createBySuccess(user); } return ServerResponse.createByErrorMessage("用户未登录,无法获取用户信息!"); } }
写回答
2回答
-
Endrong
2017-08-18
iUserService 加上注解 自动赋值 再试试 空指针的原因大概就是iUserService并没有赋值的原因
012017-08-18 -
Endrong
2017-08-17
你可以试一下 post请求的时候 参数设置改成这样
然后建议你把UserController的代码贴出来
022017-08-17
相似问题