-
Notifications
You must be signed in to change notification settings - Fork 38
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
1 parent
9ff7311
commit 7b03362
Showing
37 changed files
with
2,454 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,80 @@ | ||
# Getting started with Java | ||
|
||
Prismic makes it easy to get started on a new Java project by providing a specific Java starter project. | ||
|
||
## Create a content repository | ||
|
||
A content repository is where you define, edit, and publish content. | ||
|
||
[**Create Repository**](https://prismic.io/dashboard/new-repository/) | ||
|
||
Once your repo is created, setup your custom types and create some content. | ||
|
||
## Download the starter project | ||
|
||
The Java starter project allows you to query and retrieve content from your Prismic repository and integrate it into your website templates. It's the easiest way to get started with a new project. | ||
|
||
[**Download SDK**](https://github.com/prismicio/java-springmvc-starter/archive/master.zip) | ||
|
||
## Configure and run your project | ||
|
||
Unzip the downloaded file in the desired location for your project. | ||
|
||
Replace "lesbonneschoses" in the repository url in your `src/main/webapp/WEB-INF/web.xml` file with your repository name. | ||
|
||
```html | ||
<!-- in the filter definition, in web.xml --> | ||
<init-param> | ||
<param-name>endpoint</param-name> | ||
<param-value>https://your-repo-name.cdn.prismic.io/api</param-value> | ||
<!-- param-name>accessToken</param-name> | ||
<param-value>xxxx</param-value --> | ||
</init-param> | ||
``` | ||
|
||
Fire up a terminal (command prompt or similar on Windows), point it to your project location and run the following command. Note that you will need to have [Maven](https://maven.apache.org/) installed on your machine. | ||
|
||
```bash | ||
mvn jetty:run | ||
``` | ||
|
||
You can now open your browser to [http://localhost:8080](http://localhost:8080) and see the project running. It will list your documents which you can click on to get a simple preview of the content. | ||
|
||
> **Pagination of API Results** | ||
> | ||
> When querying a Prismic repository, your results will be paginated. By default, there are 20 documents per page in the results. You can read more about how to manipulate the pagination in the [Pagination for Results](../02-query-the-api/14-pagination-for-results.md) page. | ||
## And your Prismic journey begins! | ||
|
||
Now you're all set to start building your website with Prismic content management. Here are the next steps you need to take. | ||
|
||
### Define your Custom Types | ||
|
||
First you'll need to model your pages, posts, events, etc. into your Custom Types. Refer to our user-guides to learn more about [constructing your Custom Types](https://user-guides.prismic.io/content-modeling-and-custom-types) using our easy drag-n-drop builder. | ||
|
||
### Query your documents | ||
|
||
After you've created and published some documents in your repository, you’ll be able to query the API to retrieve your content. We provide explanations and plenty of examples of queries in the documentation. Start by learning more on the [How to Query the API](../02-query-the-api/01-how-to-query-the-api.md) page. | ||
|
||
### Integrate content into your templates | ||
|
||
The last step is to integrate the content into your templates. Helper functions are provided for each content field type to make integration as easy as possible. Check out our [Templating documentation](../03-templating/01-the-document-object.md) to learn more. | ||
|
||
## Working with existing projects | ||
|
||
If you: | ||
|
||
- Already have a website you want to integrate Prismic to | ||
- Want to use a different framework than proposed in the SDK | ||
- or simply prefer to use your own tools to bootstrap the project | ||
|
||
You can simply add the library as a dependency as shown below and then follow the instructions in these documentation pages to get up and running. | ||
|
||
```html | ||
<!-- Check Maven Central to make sure you're using the latest version --> | ||
<dependency> | ||
<groupId>io.prismic</groupId> | ||
<artifactId>java-kit</artifactId> | ||
<version>1.5.0</version> | ||
</dependency> | ||
``` |
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,87 @@ | ||
# How to query the API | ||
|
||
In order to retrieve the content from your repository, you will need to query the repository API. When you create your query you will specify exactly what it is you are looking for. You could query the repository for all the documents of certain type or retrieve the one specific document you need. | ||
|
||
Let's take a look at how to put together queries for whatever case you need. | ||
|
||
## The Basics | ||
|
||
When retrieving content from your Prismic repository, here's what a typical query looks like. | ||
|
||
```java | ||
Response response = api.query(Predicates.at("document.type", "blog-post")) | ||
.orderings("my.blog-post.date desc") | ||
.submit(); | ||
List<Document> documents = response.getResults(); | ||
``` | ||
|
||
This is the basic format of a query. In the query you have two parts, the _Predicate_ and the _options_. | ||
|
||
## Predicates | ||
|
||
In the above example we had the following predicate. | ||
|
||
```java | ||
Predicates.at("document.type", "blog-post") | ||
``` | ||
|
||
The predicate(s) will define which documents are retrieved from the content repository. This particular example will retrieve all of the documents of the type "blog-post". | ||
|
||
The first part, "document.type" is the *path*, or what the query will be looking for. The second part of the predicate in the above example is the _value_, which in this case is:\*\* \*\*"blog-post". | ||
|
||
You can combine more than one predicate together to refine your query. You just need to comma-separate your predicates in the query method as shown below. | ||
|
||
```java | ||
.query( | ||
Predicates.at("document.type", "blog-post"), | ||
Predicates.at("document.tags", Arrays.asList("featured")) | ||
) | ||
``` | ||
|
||
This particular query will retrieve all the documents of the "blog-post" type that also have the tag "featured". | ||
|
||
## Options | ||
|
||
In the second part of the query, you can include the options needed for that query. In the above example we used _desc \_to retrieve the response in descending order, you can also use \_asc_ for ascending order. | ||
|
||
```java | ||
.orderings("my.blog-post.date desc") | ||
``` | ||
|
||
The following options let you specify how the returned list of documents will be ordered. You can include more than one option, by adding al the needed options as shown below. | ||
|
||
```java | ||
.pageSize(10) | ||
.page(2) | ||
``` | ||
|
||
You will find a list and description of all the available options on the [Query Options Reference](../02-query-the-api/03-query-options-reference.md) page. | ||
|
||
> **Pagination of API Results** | ||
> | ||
> When querying a Prismic repository, your results will be paginated. By default, there are 20 documents per page in the results. You can read more about how to manipulate the pagination in the [Pagination for Results](../02-query-the-api/14-pagination-for-results.md) page. | ||
## Submit the query | ||
|
||
After specifying the query and the options, you need to submit the query using the following method. | ||
|
||
```java | ||
.submit() | ||
``` | ||
|
||
## Putting it all together | ||
|
||
Here's another example of a more advanced query with multiple predicates and multiple options: | ||
|
||
```java | ||
Response response = api.query( | ||
Predicates.at("document.type", "blog-post"), | ||
Predicates.at("document.tags", Arrays.asList("featured")) | ||
).orderings("my.blog-post.date desc") | ||
.pageSize(10) | ||
.page(1) | ||
.submit(); | ||
List<Document> documents = response.getResults(); | ||
``` | ||
|
||
Whenever you query your content, you end up with the response object stored in the defined variable. In this example the variable was called _response_ |
Oops, something went wrong.