In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Springmvc tutorial series
Best tutorial in the History of springmvc (2)
Best tutorial in the History of springmvc (1)
Best tutorial in the History of springmvc (3)
Best tutorial in the History of springmvc (4)
First, integrate mybatis
In order to better learn the integrated development method of springmvc and mybatis, it is necessary to integrate springmvc and mybatis.
Integration goal: springmvc is used in the control layer and mybatis is used in the persistence layer.
1.1 demand
Realize commodity query list and query commodity information from MySQL database.
1.2 jar package
Including: spring (including springmvc), mybatis, mybatis-spring integration package, database driver, third-party connection pool.
1.3 Dao
Goal:
1. Spring manages SqlSessionFactory and mapper
1.3.1 sqlMapConfig.xml
Create mybatis/sqlMapConfig.xml under classpath
1.3.2 applicationContext-dao.xml
Configure data source, transaction management, configure SqlSessionFactory, mapper scanner.
1.3.3 ItemsMapper.xml
And items.name like'% ${items.name}%'
Select * from items
1.3.4 ItemsMapper.java
Public interface ItemsMapper {
/ / Product list
Public List findItemsList (QueryVo queryVo) throws Exception
}
1.4 Service
Goal:
1. Service is managed by spring
2. Spring controls the transaction of Service.
1.4.1 applicationContext-service.xml
Configure the service interface.
1.4.2 applicationContext-transaction.xml
Configure the transaction manager.
1.4.3 OrderService
Public interface OrderService {
/ / Product query list
Public List findItemsList (QueryVo queryVo) throws Exception
}
@ Autowired
Private ItemsMapper itemsMapper
@ Override
Public List findItemsList (QueryVo queryVo) throws Exception {
/ / query commodity information
Return itemsMapper.findItemsList (queryVo)
}
}
1.5 Action
1.5.1 springmvc.xml
1.5.2 web.xml
Load the spring container and configure the springmvc front controller.
Springmvc
ContextConfigLocation
/ WEB-INF/classes/spring/applicationContext.xml,/WEB-INF/classes/spring/applicationContext-*.xml
Org.springframework.web.context.ContextLoaderListener
CharacterEncodingFilter
Org.springframework.web.filter.CharacterEncodingFilter
Encoding
Utf-8
CharacterEncodingFilter
/ *
Springmvc
Org.springframework.web.servlet.DispatcherServlet
ContextConfigLocation
Classpath:spring/springmvc.xml
one
Springmvc
* .action
Index.html
Index.htm
Index.jsp
Default.html
Default.htm
Default.jsp
1.5.3 OrderController
@ Controller
Public class OrderController {
@ Autowired
Private OrderService orderService
@ RequestMapping ("/ queryItem.action")
Public ModelAndView queryItem () throws Exception {
/ / Product list
List itemsList = orderService.findItemsList (null)
/ / create modelAndView to populate data and set view
ModelAndView modelAndView = new ModelAndView ()
/ / populate data
ModelAndView.addObject ("itemsList", itemsList)
/ / View
ModelAndView.setViewName ("order/itemsList")
Return modelAndView
}
}
1.6 Test
Http://localhost:8080/springmvc_mybatis/queryItem.action
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.