目标c中的常规做法是将控制器用作各种协议实现的委托.我在谈论使用iOS SDK时,或者是否有一个单独的类来接管代理卷?或者它只是一个最适合场景的情况?我对Objective c中的最佳实践非常好奇,因为我正在学习单独编写代码并且没有"现实世界"专家可以转向.
我是棱角分明的,所以也许我错过了一些东西.
在我的注册表格中,我需要用户提供一个位置.根据他们是否允许/支持navigator.geolocation,我想显示一个下拉列表来选择一个位置.
控制器.
$scope.showLoc = true;
if(navigator && navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(pos){
$scope.showLoc = false;
},function(err){
$scope.showLoc = true;
});
}
Run Code Online (Sandbox Code Playgroud)
和我的形式:
<form class="form-horizontal" name="register" ng-controller="RegisterCtrl" ng-submit="registerUser()"> ....
<div ng-show="showLoc" accesskey="">
test
</div>
....
</form>
Run Code Online (Sandbox Code Playgroud)
这种方法对我不起作用.任何见解将不胜感激.
我有一个使用Spring 3.1的Rest Controller方法,如下所示:
@RequestMapping(value="/user", method=RequestMethod.POST, consumes={MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> addUser(@RequestBody @Valid User user){
System.out.println("called / user method");
try{
user = userService.addUser(user);
return responseBuilder.addApiResourceSucceeded(user,null);
}catch(Exception e){
return responseBuilder.apiActionFailed("user already exists", HttpStatus.CONFLICT);
}
}
Run Code Online (Sandbox Code Playgroud)
我有测试,看起来像这样:
@Before
public void setUp() {
adapter = new AnnotationMethodHandlerAdapter();
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
mapper = new ObjectMapper();
}
@Test
public void testAddUser() throws Exception {
request.setMethod("POST");
request.setContentType(MediaType.APPLICATION_JSON_VALUE);
request.setRequestURI("/user");
ObjectNode userJson = mapper.createObjectNode();
userJson.put("userId", "jonnybz");
userJson.put("email", "test@gmail.com");
userJson.put("password", "password");
userJson.put("longitude",-10.127205999);
userJson.put("latitude", 57.252269);
ArrayNode arrNode = …Run Code Online (Sandbox Code Playgroud) angularjs ×1
cocoa-touch ×1
ios ×1
iphone ×1
javascript ×1
json ×1
objective-c ×1
rest ×1
spring-mvc ×1