I am unable to display byte image in thymleaf which is come from database as blob then convert to byte[], when I fetch image from database that query successfully implemented, but it is unable to display in thymleaf here below is code
DaoImpl code this function in daoimpl for retriving image from database
in this fuction by using query blob is selected from database then blob is cast in byte and byte directly send to controller
@Override
public byte[] stockProductMenData()
{
Session session = getSession();
byte[] Imagebytes = null;
Query query = session.createQuery("select sp.stockProductPic "
+ "from StockType st,StockProduct sp"
+ " where st.stockTypeId=sp.stockTypeId and st.stockTypeName = :stockTypeName");
query.setParameter("stockTypeName","MEN");
List<Blob> list = query.list();
System.out.println("List size :"+list.size());
Iterator<Blob> itr = list.iterator();
while(itr.hasNext())
{
Blob blob = itr.next();
try {
Imagebytes =blob.getBytes(1,(int) blob.length());
System.out.println("dddddd"+Imagebytes);
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("eeeeeee"+e);
}
}
controller in controller we recieve byte array and encoded in base64 and send to thymleaf page
@RequestMapping(value = "/mens" , method = RequestMethod.GET)
public ModelAndView custMen()
{
ModelAndView modelAndView =new ModelAndView();
byte[] picContent = customerDao.stockProductMenData();
byte[] encoded = Base64.getEncoder().encode(picContent);
System.out.println("ssssssssss"+picContent);
modelAndView.addObject("pic",encoded);
modelAndView.setViewName("mens");
return modelAndView;
}
Front end with thymleaf here we recieve object of pic and display using thymleaf but pic is not display
<a href="mens_single.html">
<div class="cbp-pgitem a3ls">
<div class="cbp-pgitem-flip">
<img alt="Image" th:field="${pic}" width="250" height="250"/>
</div>
</div>