我使用Ubuntu并在其上安装了Curl.我想用Curl测试我的Spring REST应用程序.我在Java端编写了我的POST代码.但是,我想用Curl测试它.我正在尝试发布JSON数据.示例数据如下:
{"value":"30","type":"Tip 3","targetModule":"Target 3","configurationGroup":null,"name":"Configuration Deneme 3","description":null,"identity":"Configuration Deneme 3","version":0,"systemId":3,"active":true}
Run Code Online (Sandbox Code Playgroud)
我用这个命令:
curl -i \
-H "Accept: application/json" \
-H "X-HTTP-Method-Override: PUT" \
-X POST -d "value":"30","type":"Tip 3","targetModule":"Target 3","configurationGroup":null,"name":"Configuration Deneme 3","description":null,"identity":"Configuration Deneme 3","version":0,"systemId":3,"active":true \
http://localhost:8080/xx/xxx/xxxx
Run Code Online (Sandbox Code Playgroud)
它返回此错误:
HTTP/1.1 415 Unsupported Media Type
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Length: 1051
Date: Wed, 24 Aug 2011 08:50:17 GMT
Run Code Online (Sandbox Code Playgroud)
错误描述如下:
服务器拒绝此请求,因为请求实体的格式不受所请求方法()的请求资源支持.
Tomcat日志:"POST/ui/webapp/conf/clear HTTP/1.1"415 1051
关于Curl命令的正确格式的任何想法?
编辑:
这是我的Java端PUT代码(我测试过GET和DELETE,它们有效)
@RequestMapping(method = RequestMethod.PUT)
public Configuration updateConfiguration(HttpServletResponse response, @RequestBody Configuration configuration) { //consider @Valid tag
configuration.setName("PUT worked");
//todo If error occurs …Run Code Online (Sandbox Code Playgroud) 能@Component,@Repository并@Service注释互换在Spring中,还是他们提供任何特殊的功能,除了作为一个符号设备?
换句话说,如果我有一个Service类并且我将注释更改@Service为@Component,它仍然会以相同的方式运行吗?
或者注释是否也会影响类的行为和功能?
关于控制(IoC)的反转是如何工作的,我有点困惑Spring.
假设我有一个名为的UserServiceImpl实现UserService接口的服务类.
怎么会这样@Autowired?
而在我Controllers,我怎么会instantiate在instance这个服务的?
我会做以下吗?
UserService userService = new UserServiceImpl();
Run Code Online (Sandbox Code Playgroud) 在尝试将具有双向关联的JPA对象转换为JSON时,我不断获取
org.codehaus.jackson.map.JsonMappingException: Infinite recursion (StackOverflowError)
Run Code Online (Sandbox Code Playgroud)
我找到的只是这个线程,基本上建议避免双向关联.有没有人对这个春天的bug有一个解决方法?
------编辑2010-07-24 16:26:22 -------
Codesnippets:
业务对象1:
@Entity
@Table(name = "ta_trainee", uniqueConstraints = {@UniqueConstraint(columnNames = {"id"})})
public class Trainee extends BusinessObject {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
@Column(name = "id", nullable = false)
private Integer id;
@Column(name = "name", nullable = true)
private String name;
@Column(name = "surname", nullable = true)
private String surname;
@OneToMany(mappedBy = "trainee", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@Column(nullable = true)
private Set<BodyStat> bodyStats;
@OneToMany(mappedBy = "trainee", fetch = FetchType.EAGER, …Run Code Online (Sandbox Code Playgroud) 我使用Spring MVC作为一个简单的JSON API,@ResponseBody基于以下方法.(我已经有一个直接生成JSON的服务层.)
@RequestMapping(value = "/matches/{matchId}", produces = "application/json")
@ResponseBody
public String match(@PathVariable String matchId) {
String json = matchService.getMatchJson(matchId);
if (json == null) {
// TODO: how to respond with e.g. 400 "bad request"?
}
return json;
}
Run Code Online (Sandbox Code Playgroud)
问题是,在给定的场景中,用HTTP 400错误响应的最简单,最干净的方法是什么?
我确实遇到过这样的方法:
return new ResponseEntity(HttpStatus.BAD_REQUEST);
Run Code Online (Sandbox Code Playgroud)
...但我不能在这里使用它,因为我的方法的返回类型是String,而不是ResponseEntity.
@ModelAttributeSpring MVC 的目的和用途是什么?
这是Spring MVC @PathVariable被截断的问题的延续
Spring论坛声明它已修复(3.2版本)作为ContentNegotiationManager的一部分.见下面的链接.
https://jira.springsource.org/browse/SPR-6164
https://jira.springsource.org/browse/SPR-7632
在我的应用程序中,带有.com的requestParameter被截断.
谁能解释我如何使用这个新功能?它是如何在xml中配置的?
我有这个问题:
org.hibernate.LazyInitializationException:懒得初始化角色集合:mvc3.model.Topic.comments,没有会话或会话被关闭
这是模型:
@Entity
@Table(name = "T_TOPIC")
public class Topic {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
@ManyToOne
@JoinColumn(name="USER_ID")
private User author;
@Enumerated(EnumType.STRING)
private Tag topicTag;
private String name;
private String text;
@OneToMany(mappedBy = "topic", cascade = CascadeType.ALL)
private Collection<Comment> comments = new LinkedHashSet<Comment>();
...
public Collection<Comment> getComments() {
return comments;
}
}
Run Code Online (Sandbox Code Playgroud)
调用模型的控制器如下所示:
@Controller
@RequestMapping(value = "/topic")
public class TopicController {
@Autowired
private TopicService service;
private static final Logger logger = LoggerFactory.getLogger(TopicController.class);
@RequestMapping(value = "/details/{topicId}", method = RequestMethod.GET)
public ModelAndView …Run Code Online (Sandbox Code Playgroud) 弹簧@Controller和@RestController注释之间的区别.
可以@Controller注解同时用于Web MVC框架和REST的应用程序?
如果是,我们如何区分它是Web MVC还是REST应用程序.
是什么区别@RequestParam和@PathVariable同时处理的特殊字符?
+被@RequestParam空间接受了.
在这种情况下@PathVariable,+被接受为+.
spring-mvc ×10
java ×8
spring ×7
json ×2
rest ×2
annotations ×1
autowired ×1
curl ×1
hibernate ×1
http-error ×1
http-headers ×1
jackson ×1
jsp ×1
orm ×1