-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
473 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
|
||
## Run Jetty Server ## | ||
|
||
mvn clean jetty:run | ||
|
||
|
||
## Connect & Write to DB ## | ||
|
||
http://localhost:9090/write.html?title=aaa&content=bbb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>ex.spring.db</groupId> | ||
<artifactId>spring-db-parent</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
<groupId>ex.spring.db</groupId> | ||
<artifactId>spring-db-springdata-mongo</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>07-mysql-spring-springdata-mongo</name> | ||
<description>example #07 | ||
MongoDB + Spring Data</description> | ||
|
||
<properties> | ||
|
||
<!-- Generic properties --> | ||
<java.version>1.8</java.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
|
||
<!-- Spring --> | ||
<spring-framework.version>4.3.5.RELEASE</spring-framework.version> | ||
<spring-data.version>1.10.6.RELEASE</spring-data.version> | ||
|
||
<!-- Logging --> | ||
<logback.version>1.0.13</logback.version> | ||
<slf4j.version>1.7.5</slf4j.version> | ||
|
||
<!-- Test --> | ||
<junit.version>4.11</junit.version> | ||
|
||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-jdbc</artifactId> | ||
<version>${spring-framework.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-webmvc</artifactId> | ||
<version>${spring-framework.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-tx</artifactId> | ||
<version>${spring-framework.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-orm</artifactId> | ||
<version>${spring-framework.version}</version> | ||
</dependency> | ||
<!-- <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId> | ||
<version>${spring-data.version}</version> </dependency> --> | ||
|
||
<dependency> | ||
<groupId>org.springframework.data</groupId> | ||
<artifactId>spring-data-mongodb</artifactId> | ||
<version>1.9.6.RELEASE</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>commons-dbcp</groupId> | ||
<artifactId>commons-dbcp</artifactId> | ||
<version>1.4</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>jstl</artifactId> | ||
<version>1.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.mortbay.jetty</groupId> | ||
<artifactId>jsp-2.1</artifactId> | ||
<version>6.0.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.mortbay.jetty</groupId> | ||
<artifactId>maven-jetty-plugin</artifactId> | ||
<version>6.1.26</version> | ||
<configuration> | ||
<jettyEnvXml>src/main/jetty/jetty-config.xml</jettyEnvXml> | ||
<useTestClasspath>true</useTestClasspath> | ||
<connectors> | ||
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> | ||
<port>9090</port> | ||
<maxIdleTime>60000</maxIdleTime> | ||
</connector> | ||
</connectors> | ||
<contextPath>/</contextPath> | ||
<scanIntervalSeconds>10</scanIntervalSeconds> | ||
<stopKey>foo</stopKey> | ||
<stopPort>9999</stopPort> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<!-- or whatever version you use --> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<packaging>war</packaging> | ||
</project> |
31 changes: 31 additions & 0 deletions
31
07-spring-db-jpa-mongo/src/main/java/ex/spring/controller/IndexController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package ex.spring.controller; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
import ex.spring.service.ParentService; | ||
|
||
@Controller | ||
public class IndexController { | ||
@Autowired private ParentService bitmapService; | ||
|
||
@RequestMapping("/index.html") | ||
public String index(Model model){ | ||
// List<Article> list = boardService.list(); | ||
// model.addAttribute("list", list); | ||
return "index"; | ||
} | ||
|
||
@RequestMapping("/write.html") | ||
public String write(@RequestParam String title, @RequestParam String content, Model model){ | ||
// System.out.println("params : " + param); | ||
// String title = (String) param.get("title"); | ||
// String content = (String) param.get("content"); | ||
// boardService.write(new Article(title, content)); | ||
bitmapService.save(new Long(10)); | ||
return index(model); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
07-spring-db-jpa-mongo/src/main/java/ex/spring/service/ParentService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ex.spring.service; | ||
|
||
public interface ParentService { | ||
void save(Long id); | ||
} |
66 changes: 66 additions & 0 deletions
66
07-spring-db-jpa-mongo/src/main/java/ex/spring/service/ParentServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package ex.spring.service; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class ParentServiceImpl implements ParentService { | ||
private static Logger log = LoggerFactory.getLogger(ParentServiceImpl.class); | ||
@Autowired private MongoTemplate mt; | ||
// @Autowired private ParentRepository 성적Repository; | ||
|
||
@Override | ||
public void save(Long id) { | ||
log.info("성적Service.save()"); | ||
mt.save(new Person("lhs", 10)); | ||
// Parent b = new Parent(); | ||
// b.set성명("이현수"); | ||
// b.setUser(new User("homevalue")); | ||
// 성적Repository.save(b); | ||
|
||
// System.out.println(b.getId()); | ||
// List<Child> m = new ArrayList<>(); | ||
// Child e = new Child(); | ||
// e.set성적표(b.getId()); | ||
// e.setParentId(parentId); | ||
// m.add(e); | ||
|
||
// Child e2 = new Child(); | ||
// e2.set성적표(b.getId()); | ||
// e.setParentId(parentId); | ||
// m.add(e2); | ||
// | ||
// b.set중간고사(m); | ||
// 성적Repository.save(b); | ||
} | ||
|
||
} | ||
|
||
class Person{ | ||
private String name; | ||
private int age; | ||
|
||
public Person(String name, int age){ | ||
this.name = name; | ||
this.age = age; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public int getAge() { | ||
return age; | ||
} | ||
|
||
public void setAge(int age) { | ||
this.age = age; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Configure class="org.mortbay.jetty.webapp.WebAppContext"> | ||
<Array id="plusConfig" type="java.lang.String"> | ||
<Item>org.mortbay.jetty.webapp.WebInfConfiguration</Item> | ||
<Item>org.mortbay.jetty.plus.webapp.EnvConfiguration</Item> | ||
<Item>org.mortbay.jetty.plus.webapp.Configuration</Item> | ||
<Item>org.mortbay.jetty.webapp.JettyWebXmlConfiguration</Item> | ||
<Item>org.mortbay.jetty.webapp.TagLibConfiguration</Item> | ||
</Array> | ||
<New id="webAppContext" class="org.mortbay.jetty.webapp.WebAppContext"> | ||
<Set name="ConfigurationClasses"> | ||
<Ref id="plusConfig" /> | ||
</Set> | ||
</New> | ||
|
||
<!-- <New id="mongodb" class="org.mortbay.jetty.plus.naming.Resource"> | ||
<Arg>jdbc/mongodb</Arg> | ||
<Arg> | ||
<New class="cdata.jdbc.mongodb.MongoDBDriver"> | ||
<Set name="url">jdbc:mongodb:</Set> | ||
<Set name="Server">10.0.0.227</Set> | ||
<Set name="Port">27017</Set> | ||
<Set name="Database">mongo</Set> | ||
<Set name="User">druwa</Set> | ||
<Set name="Password">1234</Set> | ||
</New> | ||
</Arg> | ||
</New> --> | ||
</Configure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:p="http://www.springframework.org/schema/p" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> | ||
|
||
<context:component-scan base-package="ex.spring.dao, ex.spring.service" /> | ||
<context:annotation-config /> | ||
|
||
</beans> |
5 changes: 5 additions & 0 deletions
5
07-spring-db-jpa-mongo/src/main/resources/database-scripts/create-database.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
drop database jpa; | ||
|
||
create database jpa character set = 'utf8' collate = 'utf8_unicode_ci'; | ||
|
||
use jpa; |
39 changes: 39 additions & 0 deletions
39
07-spring-db-jpa-mongo/src/main/resources/database-scripts/create-tables-hangul.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
DROP TABLE IF EXISTS `sample_table`; | ||
|
||
create table IF NOT EXISTS sample_table ( | ||
id int(10) not null AUTO_INCREMENT, | ||
sample_name varchar(100) not null, | ||
code varchar(20) not null, | ||
create_datetime datetime not null, | ||
primary key(id) | ||
); | ||
|
||
DROP TABLE IF EXISTS `1F005`; | ||
|
||
CREATE TABLE IF NOT EXISTS 1F005 ( | ||
uid int(10) NOT NULL AUTO_INCREMENT, | ||
`성명` varchar(20), | ||
`나이` varchar(20), | ||
primary key(uid) | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS article ( | ||
id int(10) NOT NULL AUTO_INCREMENT, | ||
`이름` varchar(200) NULL, | ||
primary key(id) | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS sheet ( | ||
id int(10) NOT NULL AUTO_INCREMENT, | ||
`성명` varchar(200) NULL, | ||
`평균` varchar(200) NULL, | ||
`석차` int(10) NULL, | ||
`home` varchar(10) NULL, | ||
primary key(id) | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS grade ( | ||
sid int(10) NOT NULL AUTO_INCREMENT, | ||
parentId int(10) NULL, | ||
primary key(sid) | ||
); |
5 changes: 5 additions & 0 deletions
5
07-spring-db-jpa-mongo/src/main/resources/database-scripts/insert-data.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## Insert Data | ||
|
||
INSERT INTO sample_table (sample_name, code, create_datetime) VALUES ('lee', '0100', now()); | ||
|
||
INSERT INTO 1F005 (`성명`, `나이`) VALUES ('lhs', '20'); |
37 changes: 37 additions & 0 deletions
37
07-spring-db-jpa-mongo/src/main/resources/spring-db-mongo.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:p="http://www.springframework.org/schema/p" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xmlns:jee="http://www.springframework.org/schema/jee" | ||
xmlns:jdbc="http://www.springframework.org/schema/jdbc" | ||
xmlns:mongo="http://www.springframework.org/schema/data/mongo" | ||
xmlns:tx="http://www.springframework.org/schema/tx" | ||
xmlns:jpa="http://www.springframework.org/schema/data/jpa" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd | ||
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd | ||
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd | ||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/jdbc/spring-tx.xsd | ||
http://www.springframework.org/schema/data/mongo | ||
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd | ||
http://www.springframework.org/schema/data/jpa | ||
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"> | ||
|
||
<mongo:mongo host="10.0.0.227" port="27017" /> | ||
|
||
<mongo:db-factory id="mongo-factory" dbname="mongo" mongo-ref="mongo" username="druwa" password="1234" /> | ||
|
||
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> | ||
<constructor-arg ref="mongo-factory"/> | ||
</bean> | ||
|
||
<!-- <jdbc:initialize-database data-source="datasource"> | ||
<jdbc:script location="classpath:database-scripts/create-database.sql" /> | ||
<jdbc:script location="classpath:database-scripts/create-tables-hangul.sql" /> | ||
<jdbc:script location="classpath:database-scripts/insert-data.sql" /> | ||
</jdbc:initialize-database> | ||
--> | ||
|
||
</beans> |
19 changes: 19 additions & 0 deletions
19
07-spring-db-jpa-mongo/src/main/webapp/WEB-INF/mvc-config.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" | ||
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd | ||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> | ||
|
||
<context:component-scan base-package="ex.spring"/> | ||
|
||
<mvc:annotation-driven /> | ||
|
||
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> | ||
<!-- Example: a logical view name of 'showMessage' is mapped to '/WEB-INF/jsp/showMessage.jsp' --> | ||
<property name="prefix" value="/WEB-INF/view/"/> | ||
<property name="suffix" value=".jsp"/> | ||
</bean> | ||
|
||
</beans> |
Oops, something went wrong.