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;
|
||||
|
||||
import me.hatter.sample.common.CustomConfiguration;
|
||||
import me.hatter.sample.common.annotation.Permission;
|
||||
import me.hatter.sample.common.annotation.SystemTime;
|
||||
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.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -12,6 +14,9 @@ import java.util.Date;
|
||||
@RestController
|
||||
public class SampleController {
|
||||
|
||||
@Autowired
|
||||
CustomConfiguration.CustomObject customObject;
|
||||
|
||||
@Permission
|
||||
@GetMapping("/")
|
||||
public String home(@SystemTime Date time) {
|
||||
@@ -35,6 +40,12 @@ public class SampleController {
|
||||
return "Hello: " + id;
|
||||
}
|
||||
|
||||
@Permission
|
||||
@GetMapping("/custom-object")
|
||||
public String customObject() {
|
||||
return "Custom object: " + customObject.getName();
|
||||
}
|
||||
|
||||
@Permission
|
||||
@GetMapping("/count")
|
||||
public String count(CustomSession session) {
|
||||
|
||||
Reference in New Issue
Block a user