美文网首页
springboot-web

springboot-web

作者: 紫玥迩 | 来源:发表于2017-05-18 16:56 被阅读64次
  1. springboot 1.3.5.RELEASE支持velocity模板
    springboot 1.5.3.RELEASE不支持velocity模板(推荐使用freemarker/thymeleaf)
  2. springboot返回json不需要自己再次处理了,只需要在你的Controller上加上@RestController注解就行了,springboot会自动帮你转换为json
  3. springboot 引入fastjson
<dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.21</version>
        </dependency>
@Configuration
public class MyFastJsonConfig {

    @Bean
    public HttpMessageConverters fastJsonHttpMessageConverters(){
        FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
        FastJsonConfig fastJsonConfig = new FastJsonConfig();
        fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
        fastJsonConfig.setCharset(Charset.forName("UTF-8"));
        fastConverter.setFastJsonConfig(fastJsonConfig);
        HttpMessageConverter<?> converter = fastConverter;
        return new HttpMessageConverters(converter);
    }
}

Spring Boot使用FastJson解析JSON数据

  1. 参数传递
    Spring Boot Web项目之参数绑定
使用@RequestParam(value="")来改变参数名字
使用@RequestParam(defaultValue=""),不传参时,使用默认值
使用@RequestParam(required=true),强制必须传参数
public Result test3Id(@PathVariable("id") long id)
public Result test4(int p1,int p2)
public Result test5(@RequestParam(value="p1",defaultValue="12",required=false) Integer pp)

spring boot 学习笔记(005)提交json对象

function doajax(url1,data1,callback) {
                $.ajax({
                    type: "POST",
                    url: url1,
                    data: data1,
                    dataType: "json",
                    contentType : "application/json",
                    success: function(data){
                         console.log(data);
                        callback(data);
                    }
                })
            }
function test6() {
                var url1="http://localhost:8097/test6";
                var data1="{\"name\":\"xiaomi\",\"age\":\"22\"}";
                doajax(url1,data1,function(data){
                    
                });
            }
@RequestMapping(value="/test6")
    public Result test6(@RequestBody User user){
        Result rs = new Result();
        User u=new User();
        u.setAge(user.getAge());
        u.setName(user.getName());
        rs.setData(u);
        return rs;
    }

相关文章

  • springboot-web

    springboot 1.3.5.RELEASE支持velocity模板springboot 1.5.3.RELE...

  • SpringBoot-Web

    静态资源处理 1、外部静态资源观察springboot中web项目的自动配置类可以发现,springboot中引入...

  • SpringBoot-Web自动配置

    spring-boot-web 一、在项目中使用thymeleaf spring-boot-starter-thy...

  • SpringBoot-Web开发-1

    静态资源映射规则 我们项目中有许多的静态资源,比如,css,js等文件,这个SpringBoot怎么处理呢? 如果...

  • SpringBoot-Web开发-2

    模板引擎 前端交给我们的页面,是html页面。如果是我们以前开发,我们需要把他们转成jsp页面,jsp好处就是当我...

  • SpringBoot-Web开发-3

    SpringMVC自动配置 ① 配置了视图解析器bean;② 静态资源访问支持,包括WebJars;③ 注册了转换...

  • SpringBoot-Web开发-4

    默认访问首页 SpringBootWeb开发自动配置了,当浏览器地址输入‘/‘时自动去四个静态资源文件夹class...

  • SpringBoot-Web开发-5

    登录 templates下的页面只能通过Controller跳转实现,而static下的页面是能直接被外界访问的,...

  • SpringBoot-Web应用安全策略实现

    背景 近期项目上线,甲方要求通过安全检测才能进行验收,故针对扫描结果对系统进行了一系列的安全加固,本文对一些常见的...

网友评论

      本文标题:springboot-web

      本文链接:https://www.haomeiwen.com/subject/eresxxtx.html