Skip to content

Commit

Permalink
🐛 fixed (lets-blade#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
hellokaton committed Dec 20, 2017
1 parent f427f71 commit 5c63b60
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
10 changes: 2 additions & 8 deletions src/main/java/com/blade/mvc/handler/MethodArgument.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,8 @@ private static Object getPathParam(ParamStrut paramStrut) {
}

private static Object parseModel(Class<?> argType, Request request, String name) throws Exception {
Object obj = ReflectKit.newInstance(argType);
Field[] fields = argType.getDeclaredFields();
if (null == fields || fields.length == 0) {
return null;
}
Object obj = ReflectKit.newInstance(argType);
boolean hasField = false;

for (Field field : fields) {
field.setAccessible(true);
if ("serialVersionUID".equals(field.getName())) {
Expand All @@ -222,10 +217,9 @@ private static Object parseModel(Class<?> argType, Request request, String name)
if (fieldValue.isPresent() && StringKit.isNotBlank(fieldValue.get())) {
Object value = ReflectKit.convert(field.getType(), fieldValue.get());
field.set(obj, value);
hasField = true;
}
}
return hasField ? obj : null;
return obj;
}

}
5 changes: 3 additions & 2 deletions src/test/java/io/example/blog/controller/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.blade.mvc.annotation.GetRoute;
import com.blade.mvc.annotation.Path;
import io.example.blog.model.User;

/**
* @author biezhi
Expand All @@ -11,8 +12,8 @@
public class AuthController {

@GetRoute("login")
public void login() {
System.out.println("login");
public void login(User user) {
System.out.println("login: " + user);
}

}
15 changes: 15 additions & 0 deletions src/test/java/io/example/blog/model/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.example.blog.model;

import lombok.Data;

/**
* @author biezhi
* @date 2017/12/20
*/
@Data
public class User {

private String username;
private String password;

}

0 comments on commit 5c63b60

Please sign in to comment.