创建controller
package vip.rensiyu.springboot_helloworld_quick.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Created with IntelliJ IDEA.
* Description:
* Mail: 761472239@qq.com
* Date: 2019-09-22
* Time: 9:56
*/
//这个类的所有方法都直接返回给浏览器,对象转化成json
@Controller
@ResponseBody
// @RestController 他们的效果是一样的
public class HelloController {
//写给浏览器
@ResponseBody
@RequestMapping("/hello")
public String hello() {
return "hello quick";
}
}
-
@ResponseBody写在方法上,会将此方法的返回值返回给浏览器
如果写在类的头上,会将此类的所有的(有返回值的方法)方法的结果返回到浏览器。
同时如果返会的是对象,会自动转化为json -
@RestController 的作用和@Controller 、@ResponseBody
他们的效果是一样的
因为RestController 内部包括@Controller 、@ResponseBody
提交
在目录下shift+右键打开Git Bash
1.git init
2.git add *.py
3.git commit -m ‘first’
4.然后在Github上新建一个仓库add repository,输入仓库名和描述
5.远程关联仓库,git remote add origin git@github.com:hyqyoung(用户名)/yylc_jdpm(仓库名).git
6.开始上传文件git push -u origin master
如果第六步遇到问题:
fatal: ‘orign’ does not appear to be a git repository
fatal: Could not read from remote repository.
则先删除关联:git remote rm origin
然后再执行第五、六步,要注意的是这里命令不要用上下键去调用,可能不会更新原来的操作,需要手敲
最后一步push的时候报了如下错误:
To github.com:hyqyoung/yylc_jdpm.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:hyqyoung/yylc_jdpm.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
原因是之前在GitHub的仓库里新建了一个README的文件,没有pull到本地。
所以在Github的远程仓库里做了一些变化的话,要及时pull到本地,代码:
git pull origin master
然后再进行1到6的步骤上传代码就可以了,
但是我原来做了一步不恰当的操作,那就是
git push -u origin master -f
强制执行,导致原来的远程仓库里的东西全部被替换掉了,所以切记这种操作是不可取的,并且尽量在本地做出一些修改,然后再push到GitHub上