SpringBoot 路径访问控制

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
	
	@RequestMapping("/echo")
	public String echo(String msg) {
		return "【ECHO】" + msg;
	}

	@RequestMapping("/")
	public String home() {
		return "www.baidu.com";
	}
}

http://localhost:8080/echo?msg=hello
package com.microboot.controller;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
	
	@RequestMapping(value="/echo/{message}",method=RequestMethod.GET)
	public String echo(@PathVariable("message")String msg) {
		return "【ECHO】" + msg;
	}

	@RequestMapping("/")
	public String home() {
		return "www.baidu.com";
	}
}

http://localhost:8080/echo/hello

  4.0.0
  bootfirst
  bootfirst
  0.0.1-SNAPSHOT  
  jar
  
	
		org.springframework.boot
		spring-boot-starter-parent
		1.5.12.RELEASE
		 
	
	
	
		UTF-8
		UTF-8
		1.8
		3.0.9.RELEASE
		2.3.0
		
		
		2.2.2
		
	
	
		
			
			org.springframework.boot
			spring-boot-starter-web
		
		
			org.springframework.boot
			spring-boot-starter-test
		
       
        
            org.springframework.boot
            spring-boot-devtools
            true
           true
        
      
        
             org.springframework
              springloaded
         
	
	
	
	
		bootfirst
		
			
				org.springframework.boot
				spring-boot-maven-plugin
			
		
	
  
package com.microboot.controller;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
	
	@RequestMapping(value="/echo/{message}",method=RequestMethod.GET)
	public String echo(@PathVariable("message")String msg) {
		return "【ECHO】" + msg;
	}
	
	@RequestMapping("/mul")
	public Object mul(int num) {
		return num * 2;
	}

	@RequestMapping("/")
	public String home() {
		return "www.baidu.com";
	}
}

http://localhost:8080/mul?num=20
package com.microboot.controller;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
	
	@RequestMapping(value="/echo/{message}",method=RequestMethod.GET)
	public String echo(@PathVariable("message")String msg) {
		return "【ECHO】" + msg;
	}
	
	@RequestMapping("/mul")
	public Object mul(int num) {
		return num * 5;
	}

	@RequestMapping("/")
	public String home() {
		return "www.baidu.com";
	}
}

 

你可能感兴趣的:(SpringBoot 路径访问控制)