SSM框架開發專案--用到的註解記錄,及詳解。(先記錄,後研究,再總結---未完)
阿新 • • 發佈:2019-01-01
@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;