Springboot + JPA + Summernote 예제 - 1
- 📕 Programing/Spring
- 2021. 3. 8. 17:12
Domain
package com.kyhslam.domain;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import java.time.LocalDateTime;
@Entity
@Setter @Getter
@Table(name = "voc_article")
public class Article {
@Id @GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "article_id")
private Long id;
private String subject;
@Lob
private String content;
private LocalDateTime regDate;
}
package com.kyhslam.domain;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import java.time.LocalDateTime;
@Entity
@Setter @Getter
@Table(name = "huploadfile")
public class UploadFile {
@Id @GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "upload_id")
private Long id;
private String filename; // 실제 파일이름
private String savedName; //변형된 파일이름
private String filepath; // 저장된 파일경로
private LocalDateTime regDate; // 등록일자
}
참고로 Oracle에서는 @GeneratedValue(strategy = GenerationType.IDENTITY) 안된다.
등록화면
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%--<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>--%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP - Hello World Tutorial - penthegom</title>
</head>
<!-- include libraries(jQuery, bootstrap) -->
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet">
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.js"></script>
<!-- include summernote css/js-->
<link href="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.css" rel="stylesheet">
<script src="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.js"></script>
<body>
<div id="wrap">
<form id="articleForm" role="form" action="/article/save" method="post">
<br style="clear: both">
<h3 style="margin-bottom: 25px;">Article Form</h3>
<div class="form-group">
<input type="text" class="form-control" id="subject" name="subject" placeholder="subject" required>
</div>
<div class="form-group">
<textarea class="form-control" id="summernote" name="content" placeholder="content" maxlength="140" rows="7"></textarea>
</div>
<button type="submit" id="submit" name="submit" class="btn btn-primary pull-right">Submit Form</button>
</form>
</div>
<script>
$(document).ready(function() {
$('#summernote').summernote({
height: 300,
minHeight: null,
maxHeight: null,
focus: true,
callbacks: {
onImageUpload: function(files, editor, welEditable) {
for (var i = files.length - 1; i >= 0; i--) {
sendFile(files[i], this);
}
}
}
});
});
function sendFile(file, el) {
var form_data = new FormData();
form_data.append('file', file);
$.ajax({
data: form_data,
type: "POST",
url: '/image',
cache: false,
contentType: false,
enctype: 'multipart/form-data',
processData: false,
success: function(url) {
$(el).summernote('editor.insertImage', url);
$('#imageBoard > ul').append('<li><img src="'+url+'" width="480" height="auto"/></li>');
}
});
}
</script>
</body>
</html>
'📕 Programing > Spring' 카테고리의 다른 글
[Datatables] JPA 페이징 처리 예제 (0) | 2021.03.31 |
---|---|
Springboot + JPA + Summernote 예제 - 2 (0) | 2021.03.08 |
[Intellij] JSP 연동 후 한글깨짐 현상 (0) | 2021.01.21 |
Springboot 와 Mybatis 연동 (0) | 2020.05.19 |
톰캣에 JNDI 설정 (0) | 2014.10.12 |