In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Dependence
Org.springframework.boot spring-boot-starter-data-jpa mysql mysql-connector-java
Application-database.properties
# if there is an error when initializing the database, whether to continue to start. Spring.datasource.continue-on-error=false#jdbc driver. Automatic detection through uri by default. Spring.datasource.driver-class-name=com.mysql.jdbc.Driver#jdbc url. Urispring.datasource.url=jdbc:mysql://172.28.1.227:3310/fc?useUnicode=true&autoReconnect=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useServerPrepStmts=false# database connection user name spring.datasource.username=fcdev# data connection password spring.datasource.password=123456# fully qualified name, connection pool. Default automatic detection of classpathspring.datasource.type=com.zaxxer.hikari.HikariDataSource#sql script characters spring.datasource.sql-script-encoding=UTF-8#jdbcTemplate configuration parameter spring.jdbc.template.fetch-size=-1spring.jdbc.template.max-rows=-1spring.jdbc.template.query-timeout=60
Source code-JdbcProperties
ConfigurationProperties (prefix = "spring.jdbc") public class JdbcProperties {private final Template template = new Template (); public Template getTemplate () {return this.template;} / * * {@ code JdbcTemplate} settings. * / public static class Template {/ * Number of rows that should be fetched from the database when more rows are * needed. Use-1 to use the JDBC driver's default configuration. * / private int fetchSize =-1; / * * Maximum number of rows. Use-1 to use the JDBC driver's default configuration. * / private int maxRows =-1; / * * Query timeout. Default is to use the JDBC driver's default configuration. If a * duration suffix is not specified, seconds will be used. * / @ DurationUnit (ChronoUnit.SECONDS) private Duration queryTimeout;}}
Source code-JdbcTemplateAutoConfiguration
@ Configuration@ConditionalOnClass ({DataSource.class, JdbcTemplate.class}) @ ConditionalOnSingleCandidate (DataSource.class) @ AutoConfigureAfter (DataSourceAutoConfiguration.class) @ EnableConfigurationProperties (JdbcProperties.class) public class JdbcTemplateAutoConfiguration {@ Configuration static class JdbcTemplateConfiguration {private final DataSource dataSource; private final JdbcProperties properties; JdbcTemplateConfiguration (DataSource dataSource, JdbcProperties properties) {this.dataSource = dataSource; this.properties = properties } @ Bean @ Primary @ ConditionalOnMissingBean (JdbcOperations.class) public JdbcTemplate jdbcTemplate () {JdbcTemplate jdbcTemplate = new JdbcTemplate (this.dataSource); JdbcProperties.Template template = this.properties.getTemplate (); jdbcTemplate.setFetchSize (template.getFetchSize ()); jdbcTemplate.setMaxRows (template.getMaxRows ()) If (template.getQueryTimeout ()! = null) {jdbcTemplate .setQueryTimeout ((int) template.getQueryTimeout () .getSeconds ());} return jdbcTemplate } @ Configuration @ Import (JdbcTemplateConfiguration.class) static class NamedParameterJdbcTemplateConfiguration {@ Bean @ Primary @ ConditionalOnSingleCandidate (JdbcTemplate.class) @ ConditionalOnMissingBean (NamedParameterJdbcOperations.class) public NamedParameterJdbcTemplate namedParameterJdbcTemplate (JdbcTemplate jdbcTemplate) {return new NamedParameterJdbcTemplate (jdbcTemplate);}
JdbcTemplate usage
Repositorypublic class TestJdbcDao {@ Autowired private JdbcTemplate jdbcTemplate; public String getMenuNameById (int id) {return jdbcTemplate.queryForObject ("select name from t_sys_menu where id =?", new Object [] {id}, String.class);}}
JdbcTemplate test
@ RunWith (SpringRunner.class) @ SpringBootTestpublic class AppContextTest {@ Autowired private TestJdbcDao testJdbcDao; @ Testpublic void jdbcTest () {String menuName = testJdbcDao.getMenuNameById (1); System.out.println ("menuName =" + menuName);}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.