본문 바로가기

Spring Framework77

스프링 부트 글 업데이트 하는 방법 Long commentId = Long.parseLong(request.getParameter("comment_id")); // 글 id String commentContent = request.getParameter("content"); // 글 id로 1개 찾기 Comments comments = commentsRepository.getOne(commentId); //1개 찾아서 저장 comments.setComment_content(commentContent); // 내용 변경 commentsRepository.save(comments); //아까 찾은 객체를 다시 save 이러면 update가 된다. 2018. 11. 28.
컨트롤러에서 지정한 세션 값 타임리프에서 읽기 컨트롤러에서는 이렇게 세션에 값을 추가 할 수 있다. 1 2 HttpSession session = (HttpSession)request.getSession(); session.setAttribute("loginUser", loginUser); cs 이제 타임 리프에서 찾아본다. 이렇게 찾으면 된다. 1 2 3 Join Login Logout cs session 이라는 이름의 attribute가 있는 게 아니고. session 쓰고 attribute 이름 쓰면 접근이 된다. 2018. 11. 28.
스프링 부트 타임리프( thymeleaf )에 ajax 적용해본 경험담 스프링 부트에서는 jsp를 권장하지 않는다. 타임리프를 사용하길 권장하고 있다. 그리고. 왜 그런지 이유는 알 수 없으나. 스프링 부트 2.버전 이상부터 ajax 를 원활하게 사용 할 수 있다. 예를 들어서 1.5 버전의 스프링 부트에서 아래 코드를 작성하면 에러가 난다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 $(document).ready(function () { $.ajax({ url : "http://localhost:8080/commentList", type : "get", dataType : "xml", success : function(data) { var co.. 2018. 11. 27.
PropertyReferenceException: No property xx for type yy 에러 해결 123sort = new Sort(Sort.Direction.DESC,"id");PageRequest pageRequest = new PageRequest(0, 10,sort);commentsRepository.findAll(pageRequest);cs 위와 같이 sort 를 사용하려고 할때 PropertyReferenceException: No property xx for type yy 처럼 에러가 나오는 경우가 있다. 정렬 할 컬럼을 못찾아서 나오는 에러이다. DB 컬럼을 일단 id로 바꿨다. 자 이제 model 클래스도 똑같이 바꾼다. 12345678910111213141516171819202122@Entity@Table(name="comments")public class Comments { @Id.. 2018. 11. 26.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' 에러 해결 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested excep.. 2018. 11. 25.