Java 自学知识点

本文介绍了如何使用SpringBoot创建一个简单的Web应用,包括启动类、RESTful控制器以及使用Swagger2进行API文档生成。测试中提到的问题涉及到私有变量的注入和字符串处理。
摘要由CSDN通过智能技术生成

入口 springboot

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@SpringBootApplication

public class Demo2Application {

    public static void main(String[] args) {
        SpringApplication.run(Demo2Application.class, args);
    }

}

测试代码   字符串导进去的时候 public 能输入进去 导进去的时候,private 识别不了为null

package com.example.demo.controller;

import com.example.demo.Entity.Author;
import com.example.demo.Mapper.AuthorDaoImpl;

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


@RestController
public class HelloController {

    private AuthorDaoImpl authorDao;
    @RequestMapping(value = "/hello")
    public String hello(){

        System.out.println(111);

        return "hello springboot!";
    }



    @PostMapping("/insert")
    public Boolean add(@RequestBody Author author) {

        authorDao= new AuthorDaoImpl();
        return authorDao.insertAuthor(author);

    }

}

author.java

package com.example.demo.Entity;

public class Author {


    public Integer author_id;
    public String author_name;

    public String author_discription;


    public Integer getAuthor_id() {
        return author_id;
    }



    public Author(Integer author_id, String author_name, String author_discription) {
        this.author_id = author_id;
        this.author_name = author_name;
        this.author_discription = author_discription;

    }


    public void setAuthor_id(Integer author_id) {
        this.author_id = author_id;
    }


    public String getAuthor_name() {
        return author_name;
    }

    public void setAuthor_name(String author_name) {
        this.author_name = author_name;
    }

    public String getAuthor_discription() {
        return author_discription;
    }

    public void setAuthor_discription(String author_discription) {
        this.author_discription = author_discription;
    }


    // 此处省略set、get和toString方法

}

  • 6
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值