SpringBoot 系列-3 SpringBoot 第一个Controller

注解这块与springmvc都是一样的 我们看一个简单点例子。

package com.example.demo;



import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;



@Controller
@RequestMapping(value = "/")
public class TestController {

	@ResponseBody
    @RequestMapping(value = "/test", produces = {"application/json;charset=UTF-8"})
	public String test(String name,String age){
        return name + "," + age;
    }
}

 启动springboot 之后, 在浏览器访问

http://localhost:8080/test?name=程序员&age=18

猜你喜欢

转载自blog.csdn.net/SDN_SUPERUSER/article/details/86073814