bean
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
package me.hatter.sample.common;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class CustomConfiguration {
|
||||||
|
|
||||||
|
public static class CustomObject {
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public CustomObject(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CustomObject customObject() {
|
||||||
|
return new CustomObject("Hello: custom object");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
package me.hatter.sample.web.controller;
|
package me.hatter.sample.web.controller;
|
||||||
|
|
||||||
|
import me.hatter.sample.common.CustomConfiguration;
|
||||||
import me.hatter.sample.common.annotation.Permission;
|
import me.hatter.sample.common.annotation.Permission;
|
||||||
import me.hatter.sample.common.annotation.SystemTime;
|
import me.hatter.sample.common.annotation.SystemTime;
|
||||||
import me.hatter.sample.common.session.CustomSession;
|
import me.hatter.sample.common.session.CustomSession;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
@@ -12,6 +14,9 @@ import java.util.Date;
|
|||||||
@RestController
|
@RestController
|
||||||
public class SampleController {
|
public class SampleController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CustomConfiguration.CustomObject customObject;
|
||||||
|
|
||||||
@Permission
|
@Permission
|
||||||
@GetMapping("/")
|
@GetMapping("/")
|
||||||
public String home(@SystemTime Date time) {
|
public String home(@SystemTime Date time) {
|
||||||
@@ -35,6 +40,12 @@ public class SampleController {
|
|||||||
return "Hello: " + id;
|
return "Hello: " + id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Permission
|
||||||
|
@GetMapping("/custom-object")
|
||||||
|
public String customObject() {
|
||||||
|
return "Custom object: " + customObject.getName();
|
||||||
|
}
|
||||||
|
|
||||||
@Permission
|
@Permission
|
||||||
@GetMapping("/count")
|
@GetMapping("/count")
|
||||||
public String count(CustomSession session) {
|
public String count(CustomSession session) {
|
||||||
|
|||||||
Reference in New Issue
Block a user