Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

using spring-boot i m trying to post image but i got

org.thymeleaf.exceptions.TemplateInputException

entity class

@Entity
@Table(name="image")
public class ImageEntity {
@Column(name="imageId")
private String imageId;
@Column(name="imageName")
private String imageName;
@Column(name="type")
private String type;
/*@Column(name="size")
private long size;*/
@Column(name="imagepath")
private String path;
public ImageEntity(String imageName, String type,  String path) {
    super();
    this.imageName = imageName;
    this.type = type;
    //this.size = size;
    this.path = path;
  

Controller Class

   @Controller
   public class ImgContr {
    public static final Logger logger =LoggerFactory.getLogger(ImgContr.class);
@Autowired
public ImgService imgService;
@PostMapping("/addImage")
public ImageEntity saveImage(@RequestBody ImageEntity imgent, RedirectAttributes redirectAttributes) throws Exception 
return imgService.saveImage(imgent );
  

Domain Service

@Service
public class ImgService {
@Autowired
public ImageDao imageDao;
public ImageEntity saveImage(ImageEntity imgent) {
    ImageEntity imgEngDom=new ImageEntity();
    imgEngDom.setImageId(imgent.getImageId());
    imgEngDom.setImageName( imgent.getImageName());
    imgEngDom.setPath(imgent.getPath());
    //imgEngDom.setSize(imgent.getSize());
    imgEngDom.setType(imgent.getType());
    return imageDao.saveImage(imgEngDom);
  

ImageDAO.java

@Repository
public class ImageDao {
@PersistenceContext
private EntityManager entityManager;
@Autowired
SessionFactory sessionFactory;
public ImageEntity saveImage(ImageEntity imgEngDom) {
        Session session = null;
        try {
            session = sessionFactory.openSession();
            session.beginTransaction();
            session.save(imgEngDom);
            session.getTransaction().commit();
        } catch (Exception e) {
            session.getTransaction().rollback();
        } finally {
            session.close();
        return imgEngDom;
  

Payload Request.

"imageName": "Divya", "type" : "jpg", "path": " C:/Users/admin/Desktop"

//if i try to post image like this below in postman i got error

Error

  "timestamp": 1548408353973,
  "status": 500,
  "error": "Internal Server Error",
  "exception": "org.thymeleaf.exceptions.TemplateInputException",
  "message": "Error resolving template \"addImage\", template might not 
  exist or might not be accessible by any of the configured Template 
  Resolvers",
  "path": "/addImage"

I am new to springboot where i m wrong. Help me.

is your project is mvc supported or REST-Api ? If you want your controller to serve as an rest API then go with below solution.. It must work. @divya u – Vikrant Kashyap Jan 25, 2019 at 10:12 i have tried that error cleared but imgId is not Auto incremented..if i put@GeneratedValue(strategy=GenerationType.AUTO) this in Entity class .....and all records are not saved in database – divya u Jan 25, 2019 at 10:19 @divyau if you still facing some other problem or error or exception. Keep posting new question with appropriate code and error stack... – Vikrant Kashyap Jan 25, 2019 at 10:23 now i am facing another error that is....imageId is not generated automatically ,even i put @GeneratedValue(strategy=GenerationType.AUTO) this in Entity class ... and all data is not stored in Database – divya u Jan 25, 2019 at 10:29 no use sir..i got this error Field 'image_id' doesn't have a default value, if i add IDENTITY instead of AUTO.. – divya u Jan 25, 2019 at 10:41 i need either AUTO or IDENTITY..in Database i have checked ImageId is not AutoIncremented if i try to alter table it doesnot taken AI.. – divya u Jan 25, 2019 at 10:55

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.