In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to build the javaWeb development ssm framework, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Introduction
In learning javaweb development, the learning of commonly used frameworks is very important. By using frameworks for development, the development efficiency can be greatly improved and the workload of developers can be reduced. With the rapid development of the Internet, frameworks used in software development are also emerging one after another. At present, the most widely used framework should belong to the three major frameworks of ssm. Let's take a look at the use of ssm framework.
Note: before using SSM to build the framework, you need to know about springmvc, spring, mybatis.
Steps for building SSM framework
Note: this article is built with idea development tools, and eclipse tools are all the same.
1. Create a javaweb maven project. For more information on how to create it, refer to the previous article, "detailed steps for IDEA to build a JavaWeb project through maven".
two。 Modify the project structure, as shown in the following figure:
3. Add a mybatis-config.xml file according to the structure above
4. Add a mapper.xml file
Select * from user
5. Add a jdbc.properties file
Jdbc.driverClass=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/ssm_dbjdbc.username=rootjdbc.password=root
6. Add an applicationContext.xml file
7. Add a springmvc-servlet.xml file
8. Modify the web.xml file
EncodingFilter org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 encodingFilter / * contextConfigLocation classpath:spring/applicationContext.xml org.springframework.web.context.ContextLoaderListener springmvc org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:spring/springmvc-servlet.xml 1 springmvc /
9. Create an entity Bean, for example: User.java
Package com.cn.itcdns.domain;import java.io.Serializable;import java.util.Date;import org.springframework.format.annotation.DateTimeFormat;public class User implements Serializable {private static final long serialVersionUID = 1L; private Long id; / / username private String userName; / / password private String password; / / name private String name; / / Age private Integer age; / / Sex, 1 male, 2 female private Integer sex / / date of birth @ DateTimeFormat (pattern = "yyyy-MM-dd") private Date birthday; / / creation time private Date created; / / Update time private Date updated; public Long getId () {return id;} public void setId (Long id) {this.id = id;} public String getUserName () {return userName } public void setUserName (String userName) {this.userName = userName;} public String getPassword () {return password;} public void setPassword (String password) {this.password = password;} public String getName () {return name;} public void setName (String name) {this.name = name;} public Integer getAge () {return age } public void setAge (Integer age) {this.age = age;} public Integer getSex () {return sex;} public void setSex (Integer sex) {this.sex = sex;} public Date getBirthday () {return birthday;} public void setBirthday (Date birthday) {this.birthday = birthday;} public Date getCreated () {return created } public void setCreated (Date created) {this.created = created;} public Date getUpdated () {return updated;} public void setUpdated (Date updated) {this.updated = updated @ Override public String toString () {return "User [id=" + id + ", userName=" + userName + ".password =" + password + ", name=" + name + ", age=" + age + ", sex=" + sex + ", birthday=" + birthday + ", created=" + created + ", updated=" + updated + "]";}}
10. Create a DAO, for example: UserMapper.java
Package com.cn.itcdns.mapper;import com.cn.itcdns.domain.User;import org.springframework.stereotype.Repository;import java.util.List;@Repositorypublic interface UserMapper {List findAllUsers ();}
11. Define service interface, for example: UserService.java
Package com.cn.itcdns.service;import com.cn.itcdns.domain.User;import java.util.List;public interface UserService {/ * query all user information * @ return * / List findAllUsers ();}
twelve。 Define the implementation of UserService interface, for example: UserServiceImpl.java
Package com.cn.itcdns.service.impl;import com.cn.itcdns.domain.User;import com.cn.itcdns.mapper.UserMapper;import com.cn.itcdns.service.UserService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import java.util.List;@Servicepublic class UserServiceImpl implements UserService {@ Autowired private UserMapper userMapper; @ Override public List findAllUsers () {List list = userMapper.findAllUsers (); return list;}}
13. Define a controller controller, for example: UserController.java
Package com.cn.itcdns.controller;import java.util.List;import com.cn.itcdns.domain.User;import com.cn.itcdns.service.UserService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;@Controller@RequestMapping ("user") public class UserController {@ Autowired private UserService userService @ RequestMapping ("list") public String test1 (Model model) {List users = userService.findAllUsers (); model.addAttribute ("userList", users); return "userList";}}
14. Create a jsp page, for example: userList.jsp
Insert title here number user name age gender birth date creation time update time ${user.id} ${user.userName} ${user.name} ${user.age} Male and female
At this point, after the project has been created, the project is compiled and packaged and put into tomcat to start. The access results are as follows:
These are all the contents of the article "how to build the ssm Framework for javaWeb Development". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.