我正在使用Spring Boot
和JAX-RS
。
我正在尝试将包含multipart/form-data
文件的@ModelAttribute
映射到PUT
@CrossOrigin
@RequestMapping(value = "/category/{courseCategoryId}",
method = RequestMethod.PUT,
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<?> updateCourseCategory(
@PathVariable("courseCategoryId") long courseCategoryId,
@ModelAttribute CourseCategory category) {
// code
}
请求,该请求不起作用。它没有映射任何字段。
@Entity
@Table(name = "course_category")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,
property = "id",
scope = Long.class)
@DynamicInsert(true)
@DynamicUpdate(true)
public class CourseCategory implements Serializable{
private static final long serialVersionUID = -596261264681151471L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "category")
private String category;
@Transient
private MultipartFile imageFile;
@Column(name = "image_url")
private String imageUrl;
@Column(name = "description", columnDefinition = "Text", length = 50000)
private String description;
@Column(name= "active", columnDefinition="tinyint(1) default 1")
private boolean active = true;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "category")
@LazyCollection(LazyCollectionOption.FALSE)
private List<Courses> courses;
public void setImageFile(MultipartFile imageFile) throws IOException {
if(imageFile != null) {
this.imageUrl = DefaultConfig.uploadFile(imageFile);
}
this.imageFile = null;
}
public void setCourses(List<Courses> courses) {
courses.forEach(course -> course.setCategory(this));
this.courses = courses;
}
// other getters and setters
}
HttpServletRequest
我不想使用(select t.* from A t where t.b = :b).setParameter("b", "0123456789")
是否有任何配置或方法可以使其处于工作状态。