xgqfrms / java

java playground :shit: :cloud: πŸ‘»
https://java.xgqfrms.xyz
2 stars 0 forks source link

Spring Boot 教程 #7

Open xgqfrms opened 5 years ago

xgqfrms commented 5 years ago

Spring Boot 教程

https://gitee.com/didispace/SpringBoot-Learning

https://github.com/dyc87112/SpringBoot-Learning

http://blog.didispace.com/Spring-Boot%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/

https://www.zhihu.com/question/53729800

xgqfrms commented 5 years ago

http://www.ityouknow.com/springboot/2016/01/06/spring-boot-quick-start.html

xgqfrms commented 5 years ago

https://www.w3cschool.cn/springboot/

springboot-demo

https://www.jianshu.com/c/355260609973

https://www.jianshu.com/p/de4cdba5ced7

https://www.jianshu.com/p/7bb1a82dc745

https://github.com/cuifuan/springboot-demo

xgqfrms commented 5 years ago

Gradle vs Maven

more fast

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

xgqfrms commented 5 years ago

https://github.com/ityouknow/spring-boot-examples/issues/108

solution

image

https://www.cnblogs.com/haoliansheng/p/5866149.html

xgqfrms commented 5 years ago

https://stackoverflow.com/a/40974605/5934465

xgqfrms commented 5 years ago

how to run java jar file

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

$ java -jar app.jar
xgqfrms commented 5 years ago

spring-boot-starter-web

ε₯½ζ…’ε‘€

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

image

xgqfrms commented 5 years ago

8080

http://localhost:8080/hello

image

image

OK

image

xgqfrms commented 5 years ago

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 commented 5 years ago

java return json from controller

https://stackoverflow.com/questions/30895286/spring-mvc-how-to-return-simple-string-as-json-in-rest-controller

https://stackoverflow.com/questions/23581619/simple-string-as-json-return-value-in-spring-rest-controller

https://howtodoinjava.com/spring-restful/spring-rest-hello-world-json-example/

JSONObject

https://github.com/stleary/JSON-java http://mvnrepository.com/artifact/org.json/json

https://search.maven.org/search?q=g:org.json%20AND%20a:json&core=gav

xgqfrms commented 5 years ago

Spring Boot Web

http://www.ityouknow.com/springboot/2016/02/03/spring-boot-web.html

https://www.webjars.org/

xgqfrms commented 5 years ago

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 commented 5 years ago

Jackson

xgqfrms commented 5 years ago

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;
//         }
//     }
// }