springboot1.4.7例子

阅读更多


springboot1.4.7例子_第1张图片
 

pom.xml

 


	4.0.0
	com.chipmunk
	springbootdemo
	war
	1.0.0
	springbootdemo
	http://maven.apache.org

	
		org.springframework.boot
		spring-boot-starter-parent
		1.4.7.RELEASE
		
	
	
		UTF-8
		UTF-8
		1.7
		
	

	
		
			org.springframework.boot
			spring-boot-starter-web
			
		
		
	        org.springframework.boot
	        spring-boot-devtools
	        true
	    
		
			org.springframework.boot
			spring-boot-starter-tomcat
			provided
		
		
			org.apache.tomcat.embed
			tomcat-embed-jasper
			provided
		
		
			mysql
			mysql-connector-java
		
		
		
			org.springframework.boot
			spring-boot-starter-jdbc
		
		
		
		    org.mybatis.spring.boot
		    mybatis-spring-boot-starter
		    1.0.2
		
		
			org.springframework
			spring-test
			4.3.6.RELEASE
		
		 
	      org.springframework.boot
	      spring-boot-starter-test
	      test
	    
	    
			junit
			junit
			4.12
			test
		
		
	        com.github.pagehelper
	        pagehelper
	        4.1.0
	    
		
		    org.apache.poi
		    poi
		    3.14
		
		
		
		    org.apache.poi
		    poi-ooxml
		    3.14
		
		
		
		    org.apache.poi
		    poi-scratchpad
		    3.14
		
		
		
		    org.apache.poi
		    poi-excelant
		    3.14
		
		
		
		    org.apache.commons
		    commons-lang3
		    3.4
		
		
            com.alibaba
            druid
            1.1.0
		
		
		
			org.springframework
			springloaded
			1.2.3.RELEASE
		
		
		
			javax.servlet
			javax.servlet-api
			3.1.0
			provided
		
		
           javax.servlet
           jstl
           provided
       
	

	
		telemedicine
		
			
		        org.springframework.boot
		        spring-boot-maven-plugin
		        
			        
						org.springframework
						springloaded
						1.2.3.RELEASE
					
		        
		    
		    
		     
		     
		    
			
		
	

 

   1.main方法运行嵌入的tomcat8

 

package com.chipmunk.web;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

//@Controller
//@RestController
/**
 *  @SpringBootApplication=下面三个一起用
 *  @Configuration 
	@EnableAutoConfiguration 
	@ComponentScan
 *
 */
@SpringBootApplication
public class SpringBootTomcatMain {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SpringBootTomcatMain.class, args);
    }
}

 

   2.打包后运行,配置的tomcat,需要如下类 

 

package com.chipmunk.web;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class SpringBootTomcatWeb extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        // TODO Auto-generated method stub
        return builder.sources(SpringBootTomcatWeb.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(SpringBootTomcatWeb.class, args);
    }
}

   

   3.热部署到远程服务器,远程tomcat服务器下tomcat-users.xml添加如下代码,与pom.xml要对应

    
    
    
    
    
    
  

 

---------------------------------------------------------------------------------------------------------------------------------------------

application.properties

 

server.port=8080
server.context-path=/springbootdemo


spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.jsp

 

HelloController

package com.chipmunk.web.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller  
public class HelloController {
	
	//从 application.properties 中读取配置,如取不到默认值为Hello
	//@Value("${application.helloname:Hello2}")
	private String helloname;
	
    @RequestMapping("hello1")
    @ResponseBody
    public String hello1() {
    	System.out.println("hello1");
        return "Hello World! java";
    }
    @RequestMapping("hello2")
    @ResponseBody
    public Map hello2() {
    	System.out.println("hello2");
    	Map m = new HashMap();
    	m.put("name", "hello2");
    	return m;
    }
    @RequestMapping("hello3")
    public ModelAndView hello3() {
    	System.out.println("hello3");
    	ModelAndView mav = new ModelAndView("hello");
    	mav.addObject("name", "hello3");
    	return mav;
    }
    //@PostMapping
    @GetMapping("hello4")//==@RequestMapping(value = "/hello3", method = RequestMethod.GET)
    public String hello4(Model model) {
    	System.out.println("hello4");
    	model.addAttribute("name", "hello4");
    	return "hello";
    }

}

 

 

  • springboot1.4.7例子_第2张图片
  • 大小: 15.2 KB
  • 查看图片附件

你可能感兴趣的:(springboot1.4.7例子)