方法一:
package com.zhang.demo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
//自动装配:原理!
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello(){
//调用业务,接收前端的参数;
return "hello,World";
}
}
方法二:
package com.zhang.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/hello")
public class HelloController {
@GetMapping("/hello")
@ResponseBody
public String hello(){
return "hello";
}
}