嗨我在jsp中有来自数据库的show image的问题,我有错误:
HTTP状态400 - 必需的整数参数' id'不存在
保存在数据库中的BLOB文件正确,这是我的代码:
@Entity
@Table(name = "skis")
public class Skis {
@Id
@Column(name= "skisId")
@GeneratedValue
private Integer skisId;
@Column(name = "company", length = 20)
private String company;
@Column(name = "model", length = 20)
private String model;
@Column(name = "description", length = 200)
private String description;
@Lob
@Basic(fetch = FetchType.LAZY)
private byte[] photo;
@Repository
public interface SkisDAO extends JpaRepository<Skis, Integer> {
@Query("select s from Skis s where s.skisId = :skisId")
Skis findBySkisId(@Param("skisId") Integer skisId);
}
@Controller
@RequestMapping("/skis")
public class SkisDisplayController {
@Autowired
private SkisDAO skisDAO;
@RequestMapping(value = "/skisShow", method = RequestMethod.GET)
public void showSkis(@RequestParam("skisId") Integer skisId, HttpServletResponse response, HttpServletRequest request)
throws ServletException, IOException {
Skis skis = skisDAO.findBySkisId(skisId);
response.setContentType("image/jpeg, image/jpg, image/png, image/gif");
response.getOutputStream().write(skis.getPhoto());
response.getOutputStream().close();
}
}
JSP:
<img class="media-object img-rounded img-responsive" src="/projectName/skis/skisShow?id=${skis.skisId}" alt="photo" >
有人可以帮忙吗?