首页 > 其他分享 >SpringBoot复习:(49)NamedParameterJdbcTemplate用法

SpringBoot复习:(49)NamedParameterJdbcTemplate用法

时间:2023-08-21 17:35:19浏览次数:40  
标签:web NamedParameterJdbcTemplate SpringBoot 49 springframework parameterMap org im


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 " ;
    }


}


标签:web,NamedParameterJdbcTemplate,SpringBoot,49,springframework,parameterMap,org,im
From: https://blog.51cto.com/amadeusliu/7177769

相关文章

  • SpringBoot复习:(48)RedisAutoConfiguration自动配置类
    RedisAutoConfiguration类代码如下:可以看到在这个类中配置了2个bean:redisTemplate和stringRedisTemplate.而它通过@EnableConfigurationProperties(RedisProperties.class)注解,把配置文件中配置的Redis相关的信息引入进来了,RedisProperties代码如下:还可以看到RedisAutoConfigu......
  • SpringBoot复习:(53)TransactionInterceptor是在哪里配置的?
    我们知道SpringBoot的事务(@Transactional)最终是通过TransactionInterceptor的invoke方法调用invokeWithinTransaction方法来开启事务控制的。TransactionInterceptorbean在哪里配置的呢?在ProxyTransactionManagementConfiguration:可以看到这里创建了一个TransactionIntercept......
  • SpringBoot复习(54)用于事务处理的InfrastructureAdvisorAutoProxyCreator BeanPostProc
    从类的继承关系看InfrastructureAdvisorAutoProxyCreator是一个BeanPostProcessor.@EnableTransactionManagement注解导入了TransactionManagementConfigurationSelector类,它的代码如下:这个ImportSelector的selectImports方法返回了一个AutoProxyRegistrar,AutoProxyRegistrar代码......
  • SpringBoot复习:(38)WebServerFactoryCustomizer
    可以通过这种方式对内嵌的Servlet容器进行配置packagecn.edu.tju.config;importorg.springframework.boot.web.server.ConfigurableWebServerFactory;importorg.springframework.boot.web.server.WebServerFactory;importorg.springframework.boot.web.server.WebServerFac......
  • SpringBoot复习:(41)配置文件中配置的server开头的属性是怎么配置到Servlet容器中起作用
    ServletWebServerFactoryAutoConfiguration类:可以看到其中使用了@EnableConfigurationProperties导入了ServerProperties而ServerProperties通过使用@ConfigurationProperties注解导入了配置文件中已server开头的那些配置项。可以看到ServletWebServerFactory定义了一个类型为Se......
  • SpringBoot复习:(33)WebMvcAutoconfiguration内部静态类WebMvcAutoConfigurationAdapter
    WebMvcAutoconfiguration内部静态类WebMvcAutoConfigurationAdapter实现了WebMvcConfigurer接口,重写了一些方法,也就是默认对SpringMvc进行了一些配置:该静态类上有个**@Import**注解:@Import(EnableWebMvcConfiguration.class)它的父类DelegatingWebMvcConfiguration,通过注入......
  • SpringBoot如何进行统一版本的管理
    在springboot中,可以通过以下两种方式实现统一版本的管理:1、通过标签<parent>如:<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.4.1.......
  • springboot利用hutool快速生成验证码
    生成验证码publicclassVerificationCodeUtil{publicstaticVerificationCodegetVerification(){LineCaptchacaptcha=CaptchaUtil.createLineCaptcha(70,35,4,30);Stringkey=IdUtil.get32Uuid();VerificationCodeverificationCode......
  • 在springboot项目中部署vue打包的dist以及刷新遇到404的解决方法
    一、在springboot项目中部署dist新建一个springboot项目,并将dist复制到resources目录下面,同时在application.yml添加配置即可,操作结果如下图所示: 添加的配置代码如下:spring:web:resources:static-locations:"classpath:/dist"二、部署好之后刷新遇到404......
  • Springboot-starter
    1.Spring手动注入和自动注入通常情况下,系统中类和类之间是有依赖关系的,如果一个类对外提供的功能需要通过调用其他类的方法来实现的时候,说明这两个类之间存在依赖关系。example:publicclassUserService{publicvoidinsert(UserModelmodel){//插入用户信息......