mirror of
https://github.com/Estom/notes.git
synced 2026-02-06 20:14:37 +08:00
spring boot and mvc
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
package org.example;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
SpringApplication.run(App.class);
|
||||
System.out.println( "Hello World!" );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
package org.example.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.apache.catalina.Group;
|
||||
import org.apache.catalina.Role;
|
||||
import org.apache.catalina.User;
|
||||
import org.apache.catalina.UserDatabase;
|
||||
import org.springframework.boot.autoconfigure.web.ResourceProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Iterator;
|
||||
@Data
|
||||
@Configuration
|
||||
public class MyConfiguration {
|
||||
|
||||
@Bean
|
||||
public User getUser(){
|
||||
ResourceProperties resourceProperties = new ResourceProperties();
|
||||
|
||||
resourceProperties.getChain();
|
||||
|
||||
return new User() {
|
||||
@Override
|
||||
public String getFullName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFullName(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Group> getGroups() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassword(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Role> getRoles() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDatabase getUserDatabase() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUsername(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroup(Group group) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRole(Role role) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(Group group) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInRole(Role role) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(Group group) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroups() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRole(Role role) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRoles() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.example.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Controller
|
||||
public class HelloController {
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "/hello",method = RequestMethod.GET)
|
||||
public String hello(){
|
||||
return "Hello World!";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.example.controller;
|
||||
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
public class TestController {
|
||||
|
||||
@GetMapping("/params")
|
||||
public String helloWorld(Map<String,String> map,
|
||||
Model model,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response){
|
||||
|
||||
map.put("map","123");
|
||||
model.addAttribute("model","model123");
|
||||
request.setAttribute("request","request123");
|
||||
|
||||
Cookie cookie = new Cookie("cookie","cookie123");
|
||||
|
||||
return "forward:/success";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("/success")
|
||||
public Map<String,Object> success(HttpServletRequest request){
|
||||
Map<String,Object> map= new HashMap<>();
|
||||
map.put("map",request.getAttribute("map"));
|
||||
map.put("model",request.getAttribute("model"));
|
||||
map.put("request",request.getAttribute("request"));
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user