@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
//保证序列化json的时候,如果是null的对象,key也会消失
public class ServerResponse<T> implements Serializable {
@JsonIgnore
//使之不再json序列化结果当中
public boolean isSuccess() {
return this.status == ResponseCode.SUCCESS.getCode();
}
/*
* 告诉springmvc的dispatcherServlet这是一个Controller
* 然后被dispatcherServlet的上下文所管理,并且完成它的依赖注入
*/
@Controller
/*
* Controller负责处理,根目录下的URL
* /user/**下的所有路径都会被Controller所拦截
*/
@RequestMapping("/user")
//自动注入IuserService接口
@Autowired
private IUserService iUserService;
//负责处理/user/login.do 这个url 并且是由post方法方法传递过来的请求
@RequestMapping(value = "login.do", method = RequestMethod.POST)
//自动序列化成json格式
@ResponseBody
public ServerResponse<User> login(String username, String password, HttpSession session) {
//@Param("username") 使传进来的参数/user/login.do/?username=admin能够被方法识别
//@Param("username") 使传进来的参数/user/login.do/?username=admin能够被方法识别
User selectLogin(@Param("username") String username,@Param("password") String password );
@Service("iUserService")
//把service注入到Controller上,供Controller调用
public class UserServiceImpl implements IUserService {
@Autowired
private UserMapper userMapper;