spring boot 加快springmvc开发

最近接触了spring boot对其理念非常认同,spring 4.0提倡约定优于配置,spring boot对spring的配置进行简化,几乎零配置。同时对spring 需要的jar 也进行了整合,解决jar冲突的问题。下面是从spring boot 官方的开源代码,写的demo,spring boot github地址是(https://github.com/spring-projects/spring-boot)在sample是一些简单的demo.

package org.peng.demo;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.Map;

/**
 * Created by caicai on 2016/6/15.
 */
@Controller
public class SampleController {
    @Value("${application.message:Hello World}")
    String message="hello spring boot";
    @RequestMapping("/")
    @ResponseBody
    String hello(){
        return "Hello World";
    }
    @RequestMapping("/user")
    String userInfo(Map<String,Object> model){
        model.put("time",new Date());
        model.put("message", message);
        return "user_add";
    }
}

上面的controller就是简单的controller,然后@Value就是将application的值赋值message

package org.peng.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;

/**
 * Created by caicai on 2016/6/21.
 */
@SpringBootApplication
public class SampleApplication extends SpringBootServletInitializer{
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SampleApplication.class);
    }

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

上面是spring boot 的项目启动的,是用main方法启动的

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
</head>
<body>
     <h1>${message}</h1>
     <h2>time:${time}</h2>
</body>
</html>

application.properties是这个配置

spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.jsp
application.message=Hello Phil

spring boot的启动的图也很有特点
大写的spring
本人用的是idea +maven写的项目
完整代码在git@oschina,项目同时是开源的希望大家帮忙完善ssh git连接
持续更新中………

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值