2021-05-19

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-parent</artifactId>

    <version>2.4.5</version>

    <relativePath/>

    <!-- lookup parent from repository -->




</parent>

    <repositories>
        <repository>
            <id>nexus-aliyun</id>
            <name>nexus-aliyun</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

    <groupId>com.sdcet</groupId>

    <artifactId>restaurant</artifactId>

    <version>1.0-SNAPSHOT</version>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>


        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.16</version>
        </dependency>

        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.3</version>
        </dependency>
    </dependencies>

ObjectMapperDemo 类
public class ObjectMapperDemo {
    @Test
    public void test1(){

        System.out.println("Hello Junit");
    }

    @Test
    public void test2(){
        Phone phone = new Phone();
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            String jsonString = objectMapper.writeValueAsString(phone);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

    }
    @Test
    public void test3() {
        String str = """
                    {
                         "brand":"名牌手机",
                         "model":null,
                         "price":99999.99,
                         "newest":flast,
                         "newest":[
                         "Wednesday",
                         "Thursday",
                         "Friday"
                         ]
                         }
                         """;

        ObjectMapper objectMapper = new ObjectMapper();
        try {
            Phone phone = objectMapper.readValue(str.getBytes(), Phone.class);
            System.out.println("phone=" + phone);
            System.out.println("phone=" + Arrays.asList(phone.getStrArray()));
        }catch (IOException e){
            e.printStackTrace();
        }

    }
}

 


package com.sdcet.entity;
 
import java.util.Date;
 
public class User {
    private Long id;
    private String name;
    private String password;
    private String phone_num;
    private String sex;
    private Date create_time;
    private Date update_time;
 
    public Long getId() {
        return id;
    }
 
    public void setId(Long id) {
        this.id = id;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public String getPassword() {
        return password;
    }
 
    public void setPassword(String password) {
        this.password = password;
    }
 
    public String getPhone_num() {
        return phone_num;
    }
 
    public void setPhone_num(String phone_num) {
        this.phone_num = phone_num;
    }
 
    public String getSex() {
        return sex;
    }
 
    public void setSex(String sex) {
        this.sex = sex;
    }
 
    public Date getCreate_time() {
        return create_time;
    }
 
    public void setCreate_time(Date create_time) {
        this.create_time = create_time;
    }
 
    public Date getUpdate_time() {
        return update_time;
    }
 
    public void setUpdate_time(Date update_time) {
        this.update_time = update_time;
    }

}

在谷歌输出http://localhost:8080/getUser?id=1

id=在SQL设置的数字

</project>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值