In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces how to integrate mybatis in spring, the content is very detailed, interested friends can use for reference, I hope it can be helpful to you.
Mysql profile spring-jdbc.properties:
Jdbc.driverClassName=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8jdbc.username=testjdbc.password=testjdbc.filters=statjdbc.maxActive=800jdbc.initialSize=5jdbc.maxWait=60000jdbc.minIdle=5jdbc.timeBetweenEvictionRunsMillis=60000jdbc.minEvictableIdleTimeMillis=36000jdbc.validationQuery=SELECT 'x'jdbc.testWhileIdle=truejdbc.testOnBorrow=falsejdbc.testOnReturn=falsejdbc.poolPreparedStatements=truejdbc.maxPoolPreparedStatementPerConnectionSize=50
Spring-mybatis.xml:
Spring Mybatis
The configuration file in the spring context references the mybatis configuration file:
Add packaging configuration to the pom.xml of maven to ensure that packaging can include mapper.xml:
Src/main/java * * / .xml src/main/resources * * / *
Mapper interface test:
Screenshot of file location:
TestMapper.xml:
SELECT COUNT (1) FROM T1
TestMapper interface:
Package com.test.mybatis.dao;public interface TestMapper {int getCount ();}
Test the code:
Package com.test.controller;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RestController;import com.test.mybatis.dao.TestMapper RestController@RequestMapping (value= "/ test") public class TestController {private static final Logger logger = LoggerFactory.getLogger (TestController.class); @ Autowired TestMapper testMapper; @ RequestMapping (value= "/ test", method = RequestMethod.GET) public Object test (HttpServletRequest request, HttpServletResponse response) {int count = testMapper.getCount () Logger.info ("test: {}", count); return count;}
Results:
On how to integrate mybatis in spring to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.