0
点赞
收藏
分享

微信扫一扫

SpringBoot复习:(49)NamedParameterJdbcTemplate用法


package cn.edu.tju.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@RestController
public class DemoController {

    @Autowired
    private NamedParameterJdbcTemplate jdbcTemplate;

    @RequestMapping("getInfo")
    public String test(){
        Map<String, Object> parameterMap = new HashMap<>();
        parameterMap.put("age", 55);
        int result = jdbcTemplate.update("update student set username='test' " +
                "where age=:age", parameterMap);

        return "hello " ;
    }


}


举报

相关推荐

0 条评论