Ale*_*Man 8 java spring liferay-6 angularjs thymeleaf
我使用Spring,thymeleaf和AngularJS创建了一个liferay portlet应用程序.对于AngularJS和spring 之间的通信,我需要创建一些我使用的休息调用,@ResourceMapping如下所示.该应用程序工作正常,但问题是,我不知道怎么做GET,DELETE,PUTHTTP REST调用,因为@ResourceMapping没有允许指定任何方法.
@ResourceMapping(value="getUserDetail")
public void userDetail(@RequestParam long userId, ResourceResponse response) throws Exception {
Users users = new Users(userId);
// some logic
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
JSON_MAPPER.writeValue(response.getPortletOutputStream(), users);
}
Run Code Online (Sandbox Code Playgroud)
当我使用@RequestMapping而不是@ResourceMapping像下面所示的那样
@RequestMapping(value="getUserDetail", method=RequestMethod.GET)
@ResponseBody
public void userDetail(@RequestParam long userId, ResourceResponse response) throws Exception {
System.out.println("Got detail request for user with id {} "+ userId);
// UserDetail userDetail = this.userService.getPortalUserDetail(userId);
List<String> users = new ArrayList<String>();
users.add("Manu");
users.add("Lissie");
users.add("John");
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
JSON_MAPPER.writeValue(response.getPortletOutputStream(), users);
}
Run Code Online (Sandbox Code Playgroud)
我有
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping': Initialization of bean failed; nested exception is java.lang.IllegalStateException: Mode mappings conflict between method and type level: [getUserDetail] versus [view]
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我一些解决方案
@ResourceMapping@RequestMapping而不是@ResourceMapping在Liferay Spring portlet中进行REST调用REST网址getUser/12/mumbaiRESTjson作为正文而不是Request Param1. How to create different types of http calls using @ResourceMapping
Run Code Online (Sandbox Code Playgroud)
如果您想要具有完整操作(GET、POST、PUT、DELETE)的 REST Api,您需要使用@RequestMapping.
2. Can we use @RequestMapping instead of @ResourceMapping in Liferay Spring portlet for REST calls
Run Code Online (Sandbox Code Playgroud)
你应该能够使用。
3. How can we create resource based REST urls like getUser/12/mumbai
@RequestMapping(value="getUser/{userId}/mumbai", method=RequestMethod.GET)
@ResponseBody
public List<String> userDetail(@RequestParam("userId") long userId) throws Exception {
System.out.println("Got detail request for user with id {} "+ userId);
//UserDetail userDetail = this.userService.getPortalUserDetail(userId);
List<String> users = new ArrayList<String>();
users.add("Manu");
users.add("Lissie");
users.add("John");
return users;
}
4. How can we send REST json as body instead of Request Param
You can use @RequestBody
@RequestMapping(value="saveUser/{userId}", method=RequestMethod.GET)
@ResponseStatus(HttpStatus.CREATED)
public void userDetail(@RequestParam("userId") long userId, @RequestBody User user) throws Exception {
// Logic
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3843 次 |
| 最近记录: |