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 set up the SpringMVC implementation subcontext startup

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the knowledge of "how to build SpringMVC implementation sub-context startup". Many people will encounter this dilemma in the operation of actual cases, 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!

Pom.xml

4.0.0 com.hqt.toy toy01 0.0.1-SNAPSHOT org.apache.maven.plugins maven-compiler-plugin 6 6 war 4.3.7.RELEASE 8.0.28 javax.servlet javax.servlet-api 3.0.1 javax.servlet.jsp javax.servlet.jsp-api 2.3.1 Org.springframework spring-webmvc ${spring.version} org.hibernate.javax.persistence hibernate-jpa-2.0-api 1.0.1.Final org.apache.tomcat.embed tomcat-embed- Core ${tomcat.embed.version} org.apache.tomcat.embed tomcat-embed-jasper ${tomcat.embed.version} org.apache.tomcat.embed tomcat-embed-logging-juli ${tomcat.embed.version} Org.apache.commons commons-lang3 3.8

Web.xml

Springmvc org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:/dispatcher-servlet.xml 1 springmvc * .do

Dispatcher-servlet.xml

TestUserController

Import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.ModelMap;import org.springframework.web.bind.annotation.RequestMapping;@Controller@RequestMapping ("/ test_user.do") public class TestUserController {@ Autowired private TestUserService userService; @ RequestMapping (params= "method=user") public String user (TestUserEntity user, String uname, ModelMap modelMap) {System.out.println ("get foreground value:" + user.getUname ()) System.out.println ("String uname:" + uname); modelMap.addAttribute ("newname", user.getUname ()); userService.add (user.getUname ()); return "index";}}

TestUserEntity (optional)

Import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.GenerationType;import javax.persistence.Id;@Entitypublic class TestUserEntity {@ Id @ GeneratedValue (strategy=GenerationType.AUTO) private int id; private String uname; public int getId () {return id;} public void setId (int id) {this.id = id;} public String getUname () {return uname } public void setUname (String uname) {this.uname = uname;}}

TestUserService (optional)

Import org.springframework.stereotype.Service;import javax.annotation.Resource;@Servicepublic class TestUserService {@ Resource private TestUserDao userDao; public void add (String uname) {System.out.println ("UserService.add ()"); TestUserEntity user = new TestUserEntity (); user.setUname (uname); userDao.add (user);}}

TestUserDao (optional)

Import org.springframework.stereotype.Repository;@Repositorypublic class TestUserDao {public void add (TestUserEntity user) {System.out.println ("TestUserDao.add ()");}}

Index.jsp

User name: returned user name: ${newname} "how to build SpringMVC implementation subcontext launch" is introduced here, 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

Development

Wechat

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

12
Report