Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Idea SpringMVC+Spring+MyBatis+Maven

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "how to use Idea SpringMVC+Spring+MyBatis+Maven". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Idea SpringMVC+Spring+MyBatis+Maven integration

Create a project

File-New Project

Select Maven on the left, select Create from archetype on the upper right, then select webapp in the list below, and then click Next

Enter the specified content in GroupId and ArtifactId, and click Next

Direct point Next

Enter the project name, Finish

Idea automatically starts downloading the dependent package and waits for it to complete.

Project structure

You didn't have these files when the project was first built, so you manually create the missing folders (packages).

The project framework after creation:

Modify the pom.xml import dependency package plug-in

Dependency packages need to be as follows:

Spring framework

Aspectj transaction

C3p0 data source

Servlet/jsp api

Junit4

Mybatis

Mybatis spring integration

Mysql driver

Jstl

4.0.0 com.elin4it.ssm ssm war 1.0-SNAPSHOT ssm Maven Webapp http://maven.apache.org ssm org.mybatis.generator mybatis-generator-maven-plugin 1.3.2 true True 4.1.1.RELEASE org.springframework spring-core ${spring.version} org.springframework spring-web ${spring.version} Org.springframework spring-oxm ${spring.version} org.springframework spring-tx ${spring.version} org.springframework spring-jdbc ${spring.version} org.springframework Spring-webmvc ${spring.version} org.springframework spring-aop ${spring.version} org.springframework spring-context-support ${spring.version} org.springframework spring-test ${ Spring.version} org.aspectj aspectjweaver 1.8.6 org.aspectj aspectjrt 1.8.6 com.mchange c3p0 0.9.5.1 Javax.servlet servlet-api 2.5 javax.servlet.jsp jsp-api 2.1 provided junit junit 4.11 test Org.mybatis mybatis 3.3.0 org.mybatis mybatis-spring 1.2.3 mysql mysql-connector-java 5.1.6 Jstl jstl 1.2

Plug-ins require reverse engineering of mybatis

Complete pom.xml code listing:

Using mybatis reverse engineering to create mapper interfaces and xml files

User table structure

DROP TABLE IF EXISTS `user`; / *! 40101 SET @ saved_cs_client = @ @ character_set_client * /; / *! 40101 SET character_set_client = utf8 * /; CREATE TABLE `user` (`id`username` NOT NULL AUTO_INCREMENT, `username`varchar (32) NOT NULL COMMENT 'user name', `birthday', `sex`char (1) DEFAULT NULL COMMENT 'gender', `address`varchar (256e) DEFAULT NULL COMMENT 'address', PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8

Create a generatorConfig.xml file in main/resources

GeneratorConfig.xml code listing

Click the maven tab on the right side of idea, select mybatis-generator, and click the green button at the top to run

If there are no errors, mapper interface files, xml files, and pojo files should be generated automatically.

Db.properties file

Create db.properties in resources/config, which is used to describe mysql connection information

Jdbc.driver = com.mysql.jdbc.Driverjdbc.url = jdbc:mysql://127.0.0.1:3306/mybatis?characterEncoding=UTF-8jdbc.username = rootjdbc.password = SqlMapConfig file

Create a SqlMapConfig.xml file in resources/config/mybatis, which is the configuration file of Mybatis. Because it is integrated with spring, some basic configuration files are in spring. Here, the values in this file need to be written to the framework of the file.

SpringMVC profile

Create a springmvc.xml file in resources/config/spring

Spring IOC injection and event control

Create applicationContext-dao.xml, application-service.xml, applicationContext-transaction.xml files in resources/config/spring

ApplicationContext-dao.xml

Application-service.xml

ApplicationContext-transaction.xml

Web.xml file

Modify the contents of web.xml file

ContextConfigLocation classpath*:config/spring/applicationContext-*.xml org.springframework.web.context.ContextLoaderListener CharacterEncodingFilter org.springframework.web.filter.CharacterEncodingFilter encoding utf-8 CharacterEncodingFilter / * dispatcherServlet org.springframework.web.servlet.DispatcherServlet ContextConfigLocation classpath*:config/spring/springmvc.xml 1 dispatcherServlet / Service Interface and its implementation

Create a simple service with only one function to view a list of all users

UserService.java

Package com.elin4it.ssm.service;import com.elin4it.ssm.pojo.User;import java.util.List;/** * Created by Feng on 2015-7-11. * / public interface UserService {/ * find all users * @ return * @ throws Exception * / List findUser () throws Exception;}

Implementation class UserServiceImpl.java

Package com.elin4it.ssm.service;import com.elin4it.ssm.mapper.UserMapper;import com.elin4it.ssm.pojo.User;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import java.util.List;/** * Created by Feng on 2015-7-11. * / @ Servicepublic class UserServiceImpl implements UserService {/ / User Interface @ Autowired private UserMapper userMapper Public List findUser () throws Exception {/ / calls the selectByExample method in the mapper class. If the type passed in is null, it means to find List users = userMapper.selectByExample (null) unconditionally; return users;}} Controllerpackage com.elin4it.ssm.controller;import com.elin4it.ssm.pojo.User;import com.elin4it.ssm.service.UserService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller Import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.servlet.ModelAndView;import java.util.List;/** * Created by Feng on 2015-7-11. * / @ Controller@RequestMapping ("/ user") public class UserController {/ / service class @ Autowired private UserService userService / * find the user controller method used * @ return * @ throws Exception * / @ RequestMapping ("/ findUser") public ModelAndView findUser () throws Exception {ModelAndView modelAndView = new ModelAndView (); / / call the service method to get the user list List users = userService.findUser () / / add the contents of the user list to the ModelAndView modelAndView.addObject ("users", users); / / set the jsp view of the response modelAndView.setViewName ("findUser"); return modelAndView;}} view

According to the controller written earlier, the returned view is findUser, so create a findUser.jsp file in / WEB-INF/views to display the query results

FindUser ${u.id} ${u.username} ${u.birthday}

1. Use Alibaba Druid connection pool (efficient, powerful and scalable database connection pool, monitor database access performance, support Common-Logging, Log4j and JdkLog, monitor database access)

two。 Provide high concurrency JMS message processing mechanism

3. All functional modularization, all module service, all service atomization, provide an extensible service model, so that the program runs stably and never downtime.

4. Provides Wink Rest and Webservice services, so it can be deployed as an independent service platform

Framework integration:

Springmvc + Mybatis + Shiro (permission) + REST (Service) + WebService (Service) + JMS (message) + Lucene (search engine) + Quartz (scheduled scheduling) + Bootstrap Html5 (support for PC, IOS, Android)

Introduction to the framework:

Project Maven construction, real large-scale Internet architecture, to achieve high concurrency, big data processing, the whole project uses customized service ideas, to provide modular, service-oriented, atomized solution, the functional modules will be split, can be shared to all projects. The architecture adopts distributed deployment architecture, and all modules are split, so that the project is absolutely decoupled and stability trumps everything.

Continuous integration:

1. My to-do workflow service (providing Webservice services)

two。 My to-do workflow integrates JMS message services (supports high concurrency and can support thousands of system integration)

3. My tasks provide Rest services, complete daily work management, and dynamically generate my tasks, cycle tasks, scheduled mail reminders to complete tasks, etc., through the scheduled scheduling platform.

4. File upload, multithreaded download service, sending mail, short message service, department information service, product information service, information release service, my subscription service, my task service, public link, my collection service, etc.

System module:

1. User Management:

User information management (add, delete, modify, user authorization, user column management, query, etc.)

User group management (add, delete, modify, user group column authorization, column authorization, query, user group personnel add query, etc.)

User role management (add, delete, modify, user role authorization, user role column information query settings, etc.)

two。 Article Management:

Column management: query infinite pole column tree, create infinite pole column tree classification (navigation column, picture list column, article list column, article content column, etc.), delete, modify column information.

Article management: create, delete, modify articles, multi-dimensional article queries, including published, unpublished, all articles, etc. Article rich text editor, article multi-file upload, article status control and so on.

3. System Settings:

Data dictionary management: support Chinese and English information, support unlimited level classification configuration, dynamic control whether available, etc.

Department information management: support unlimited level department information in Chinese and English to add, delete, modify operation, department list, tree heart query and so on.

Log management: system log list query, online viewing, online download, etc.

Route management: integrate Baidu map API, provide line query management function

Druid Monitor (monitoring): integrate Alibaba connection pool, provide online connection pool monitoring program, including: data source, SQL monitoring, URL monitoring, Session monitoring, Spring monitoring, etc.

Website information management: operate the website content through the system configuration file, including mail server configuration, company basic information configuration and so on.

4. Integrated REST service, which can be used as an independent service platform (provides a large number of examples and testing platforms, including: file uploads and downloads, email messages, departments, products, public connections, my favorites, my tasks, information release, etc.)

5. Integrated Quartz scheduling, which can be used as a timing scheduling platform (dynamically configure scheduling classes, scheduling time, so that programs automatically perform certain services)

6. Lucene search engine, which can index documents and support document content search, keyword search, highlighted keywords, etc., so that the information can be extracted and queried in milliseconds.

7. User setting functions: including modifying user information, changing passwords, sending messages, modifying personal pictures, viewing roles, viewing user groups, administrators modifying roles, users, user groups, and so on.

8. Integrate Webservice platform, including jaxws service, CXF framework, configure double encryption authority authentication. Make service integration more secure.

9. Bootstrap html5 provides two sets of foreground environments, including CMS and e-commerce sites, to make your development more concise.

Technical points:

1. Springmvc + Mybatis integration, SpringSecurity permission control, Spring AOP transaction processing.

2. Wink Rest service, Webservice service: jaxws, CXF, etc.

3. IO stream uploads and downloads files and operates with multiple threads

4. Send mail, configure mail server, send mail based on html, plain text format

5. MD5 encryption (login password verification, encryption, etc.), unified Session, Cookie management, unified CAPTCHA verification, etc.

6. Unified configuration of database connection pool

7. Quartz scheduled task integration (directly through configuration)

8. Httpclient cracked the CAPTCHA and logged in to Unicom's recharge platform.

9. Chinese characters, English split, can be used as document keyword search and so on.

10. Base64 image processing, which supports PC,Android,IOS

11. Service Socket, Client Socket communication technology (GPRS data acquisition has been done and used in the project)

twelve。 Provides a large number of tool classes that can be used directly

13. Maven project building, you can directly do the architecture, you can improve your learning ability and make you a true architect.

That's all for the content of "how to use Idea SpringMVC+Spring+MyBatis+Maven". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report