「Spring」Assert.notNull()メソッドでNullを判別する方法

2020年10月30日

使用例1

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
public static void getUser(String userId,String depId) {
Assert.notNull(userId, "userId must not be null");
Assert.notNull(depId, "depId must not be null");
// some code
}
public static void getUser(String userId,String depId) { Assert.notNull(userId, "userId must not be null"); Assert.notNull(depId, "depId must not be null"); // some code }
public static void getUser(String userId,String depId) {
        Assert.notNull(userId, "userId must not be null");
            Assert.notNull(depId, "depId must not be null");
        // some code

  }

使用例2

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
WebApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();
Assert.notNull(ctx, "crx must not be null");
WebApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext(); Assert.notNull(ctx, "crx must not be null");
WebApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();
Assert.notNull(ctx, "crx must not be null");

使用例3

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
public List<User> getUserInfo(List<Depart> depart,String userId) {
Assert.notNull(departs, "depart must not be null.");
Assert.notNull(userId, "userId must not be null.");
// some code
}
public List<User> getUserInfo(List<Depart> depart,String userId) { Assert.notNull(departs, "depart must not be null."); Assert.notNull(userId, "userId must not be null."); // some code }
public List<User> getUserInfo(List<Depart> depart,String userId) {
       Assert.notNull(departs,  "depart must not be null.");   
       Assert.notNull(userId,  "userId must not be null.");
        // some code
  }

 

SpringMVC

Posted by arkgame