Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Boot 教程 #7

Open
xgqfrms opened this issue Jun 4, 2019 · 14 comments
Open

Spring Boot 教程 #7

xgqfrms opened this issue Jun 4, 2019 · 14 comments
Labels
Gradle & Maven & Ant Gradle & Maven & Ant Spring Boot Web & JSON Spring Boot Web & JSON Spring Boot Spring Boot Spring 5 & Spring Boot 2 Spring 5 & Spring Boot 2

Comments

@xgqfrms
Copy link
Owner

xgqfrms commented Jun 4, 2019

@xgqfrms
Copy link
Owner Author

xgqfrms commented Jun 4, 2019

Repository owner locked and limited conversation to collaborators Jun 4, 2019
@xgqfrms
Copy link
Owner Author

xgqfrms commented Jun 4, 2019

Gradle vs Maven

more fast

https://gradle.org/maven-vs-gradle/#close-notification

@xgqfrms
Copy link
Owner Author

xgqfrms commented Jun 4, 2019

@xgqfrms
Copy link
Owner Author

xgqfrms commented Jun 4, 2019

@xgqfrms
Copy link
Owner Author

xgqfrms commented Jun 4, 2019

how to run java jar file

https://stackoverflow.com/questions/394616/running-jar-file-on-windows

$ java -jar app.jar

@xgqfrms
Copy link
Owner Author

xgqfrms commented Jun 4, 2019

spring-boot-starter-web

好慢呀

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

image

@xgqfrms
Copy link
Owner Author

xgqfrms commented Jun 4, 2019

8080

http://localhost:8080/hello

image

image

OK

image

@xgqfrms
Copy link
Owner Author

xgqfrms commented Jun 4, 2019

JSON

image

package com.xgqfrms.sb.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SbController {
    @RequestMapping("/hello")
    public String index() {
        // String jsonString = {"name": "xgqfrms", "role": "admin", "id": 1234567890};
        // return "Hello World";
        return "{\"name\": \"xgqfrms\", \"role\": \"admin\", \"id\": \"1234567890\"}";
    }
}

@xgqfrms
Copy link
Owner Author

xgqfrms commented Jun 4, 2019

@xgqfrms
Copy link
Owner Author

xgqfrms commented Jun 4, 2019

add jar ??? 怎么手动台添加第三方的 jar

image

solution

https://blog.csdn.net/u012898245/article/details/79210635

image

maven search & add pom.xml dependence

https://mvnrepository.com/search?q=json

org.json/json

https://mvnrepository.com/artifact/org.json/json/20180813

@xgqfrms
Copy link
Owner Author

xgqfrms commented Jun 4, 2019

Jackson

@xgqfrms xgqfrms added Spring 5 & Spring Boot 2 Spring 5 & Spring Boot 2 Spring Boot Spring Boot Gradle & Maven & Ant Gradle & Maven & Ant labels Jun 4, 2019
@xgqfrms xgqfrms pinned this issue Jun 4, 2019
@xgqfrms xgqfrms added the Spring Boot Web & JSON Spring Boot Web & JSON label Jun 4, 2019
@xgqfrms
Copy link
Owner Author

xgqfrms commented Jun 4, 2019

image

package com.xgqfrms.sb.controller;

// import org.apache.catalina.User;
import org.json.JSONObject;

// import com.fasterxml.jackson.databind.util.JSONWrappedObject;
// import com.xgqfrms.sb.model.User;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SbController {
    // @RequestMapping("/hello")
    @RequestMapping(value = "/hello", method = RequestMethod.GET, produces = "application/json")
    public String index() {
        // String jsonString = {"name": "xgqfrms", "role": "admin", "id": 1234567890};
        // return "Hello World";
        // return "{\"name\": \"xgqfrms\", \"role\": \"admin\", \"id\":
        // \"1234567890\"}";
        // return "{\"name\": \"xgqfrms\", \"role\": \"admin\", \"id\": \"1234567890\"}";
        return JSONObject.quote("Hello World");
    }
    // public User getUser() {
    //     User user = new User();
    //     user.setUserName("xgqfrms");
    //     user.setPassWord("123456789");
    //     return user;
    // }
}

// @RestController
// public class SbController {
//     @RequestMapping("/hello")
//     public String index() {
//         private String response;
//         public StringResponse(String s) { 
//             this.response = s;
//         }
//     }
// }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Gradle & Maven & Ant Gradle & Maven & Ant Spring Boot Web & JSON Spring Boot Web & JSON Spring Boot Spring Boot Spring 5 & Spring Boot 2 Spring 5 & Spring Boot 2
Projects
None yet
Development

No branches or pull requests

1 participant