package com.pp.springboothelloworld.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
@Controller
public class HelloController {
@ResponseBody
@RequestMapping("hello")
public String hello(){
return "hello word";
}
}
使用注解@Controller对类进行注解,说明这是控制层,用 @ResponseBody注解说明将下面注解的方法的以json格式返回到页面,使用@RequestMapping(“hello”)注解意思是当浏览器输入http//127.0
0.1:8080/hello的时候,直接跳转到后台的这里进行处理。方法里面没有进行任何处理之间返回了hello word的字符串内容。
源码地址:https://gitee.com/yangforever/project-learning/tree/master/demo/SpringBoot/spring-boot-helloworld



