社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
注解说明
@Controller注解声明这个类是一个Controller
@RequestMapping注解修饰在class上时其中的值为请求父路径
@RequestMapping注解修饰在方法上时其中的值为请求路径
@@ResponseBody注解修饰在方法上时表示请求这个接口时返回内容而不是返回页面
@ResponseBody修饰在class上时表示请求这个Controller中是所以接口时都返回内容而不是页面
@Service注解修饰在class上表名这个class是一个Service
package com.imsjw.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/demo")
public class DemoController {
@ResponseBody
@RequestMapping("/test")
public String test(){
return "test";
}
}
package com.imsjw.demo.service;
import org.springframework.stereotype.Service;
@Service
public class DemoService {
}
浏览器地址栏输入 http://127.0.0.1:8080/demo/test
默认端口是8080
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!