JAVA8+SPRING+ANGULARJS Project Application

Source: Internet
Author: User

Recently there has been writing an e-order business website that uses JAVA8,SPRING,ANGULARJS to share the technology used in the project with everyone.

The first time to write a blog, where there is no need to correct the correction, please contact.

Because the project is what I do to others can not provide the source code forgive me, I do my best to let everyone understand.

First, starting with the construction of the project, I used the Gradle build project, which uses the version 2.4.

Idea 14 for the development environment, the project database uses SQL SERVER.

Spring Boot Technical Document: Http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle

You can see all the boot configuration and technology development here, for the English bad suggestions about the general understanding, I will slowly write, slowly understand, I know.

How to bring spring boot into the project is as follows:

Take a look at the Gradle Spring Boot configuration, with the latest version 1.2.3

Buildscript {
ext {
Springbootversion ="1.2.3.RELEASE"
}
repositories {
Mavenlocal ()
Jcenter ()
Maven {URL"Http://repo.spring.io/snapshot"}
Maven {URL"Http://repo.spring.io/milestone"}
Maven {URL"Http://repo.spring.io/plugins-release"}
}
dependencies {
Classpath${springbootversion}
Classpath ( "Org.springframework:springloaded:$ {Springbootversion} ")
Classpath (" org.springframework.build.gradle:propdeps-plugin:0.0.6 ")
}

}

Apply plugin Java"
apply plugin: Span style= "color: #6a8759;" > "Spring-boot"

This is a Gradle basic build.gradle configuration file. You can go to the Gradle website to learn more about using it, the same functionality as MAVEN tools. Spring is built to support these two plugins.

Configure the use of our projectSpringComponent:

It is in the Build.gradle file code below

dependencies {
compile("org.springframework.boot:spring-boot-starter-web")

testCompile("org.springframework.boot:spring-boot-starter-test")
}

We look at the contents of dependencies, compile is gradle inside a binding resource method, which can take the resource bundle we need and dependencies to load the project inside. If you use IDEA14 it will automatically help you configure, reference the class, everything is so simple.

First we add spring's spring-boot-starter-web component to the project.

Using Spring boot:

Spring boot is a high-integration spring management tool that coordinates spring components and allows you to spend less time configuring spring.

First we create a Application.java class under the project root package src/main/java/com/demo/ , which should look like this:

@SpringBootApplication
@EnableScheduling
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

}

@SpringBootApplication This is the Spring boot portal.

We write an entity bean,Src/main/java/com/demo/greeting.java as follows:

PackageCom.demo;

public classGreeting {

Private Final longId;
Private finalStringContent;

PublicGreeting (LongId,String content) {
This.Id= ID;
This. Content = content;
}

Public long getId() {
return ID;
}

Public String getcontent() {
return content;
}
}

Next we write a simple controller controllers,Src/main/java/com/demo/greetingcontroller.java as follows :

PackageCom.demo;


ImportOrg.springframework.web.bind.annotation.RequestMapping;
ImportOrg.springframework.web.bind.annotation.RequestParam;
ImportOrg.springframework.web.bind.annotation.RestController;

ImportJava.util.concurrent.atomic.AtomicLong;

@RestController
public classGreetingcontroller {

private static finalStringTemplate="Hello,%s!.";
Private finalAtomiclongCounter=NewAtomiclong ();

@RequestMapping("/greeting")
PublicGreetingGreeting(@RequestParam(value = "Name", defaultvalue = "World") String name) {
return new greeting(counter. Incrementandget (),
String. format (template, name));
}
}

@RestController indicates that the controller is a rest controller, then it returns not our common view object, it will automatically put the object JSON, which is the spring default, followed by how to return other types (Xml,excel, FILE)

Here we have written a simple spring boot application.

Run the Spring boot app:

In idea we can directly run with the right click of the application class, but we do not recommend it because it runs as you just run the local directory configuration and does not use spring boot.

We use Gradle to build so we recommend that you use Gradle to run your project. On the right side of idea you will find the Gradle display window. Just like we started with the Spring boot component already applied, Gradle config file build.gradle inside.

applyplugin: ‘java‘
applyplugin: ‘idea‘
applyplugin: ‘spring-boot‘

So we should be able to find the application program component in Gradle's tasks. These are usually the case:

And we click Bootrun to run it.

Next we visit in the browser

That should be the case. Indicates that our simple spring boot run was successful.

Next time I'll go into more detail, spring boot, Spring security,spring data, and its rest and JPA. For the JAVA8 used in the project will also involve some

Thank you, the first time to write a blog, rarely to write a blog, not so detailed, if you do not understand and questions please leave me a message, I will be the first time to reply to you.

If you are also interested in Java, welcome to explore together. Let's get here today.

JAVA8+SPRING+ANGULARJS Project Application

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.