In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how SpringMVC+myBatis can be used together. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
1. [code] controller fragment
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen
sixteen
seventeen
eighteen
nineteen
twenty
twenty-one
twenty-two
twenty-three
twenty-four
twenty-five
twenty-six
twenty-seven
twenty-eight
twenty-nine
thirty
thirty-one
thirty-two
thirty-three
thirty-four
thirty-five
thirty-six
thirty-seven
thirty-eight
thirty-nine
forty
forty-one
forty-two
forty-three
forty-four
forty-five
forty-six
forty-seven
forty-eight
forty-nine
fifty
fifty-one
fifty-two
fifty-three
fifty-four
fifty-five
fifty-six
fifty-seven
fifty-eight
fifty-nine
sixty
sixty-one
sixty-two
sixty-three
sixty-four
sixty-five
sixty-six
sixty-seven
sixty-eight
sixty-nine
seventy
Package com.wg.test
Import javax.servlet.http.HttpServletRequest
Import org.springframework.beans.factory.annotation.Autowired
Import org.springframework.stereotype.Controller
Import org.springframework.web.bind.annotation.RequestMapping
Import org.springframework.web.bind.annotation.RequestMethod
Import org.springframework.web.servlet.ModelAndView
Import com.wg.bean.User
Import com.wg.service.UserService
@ Controller
Public class UserController {
@ Autowired
Private UserService userService
@ RequestMapping (value = "regist", method = RequestMethod.POST)
Public ModelAndView regist (HttpServletRequest request, User user) {
Try {
UserService.saveUser (user)
} catch (Exception e) {
E.printStackTrace ()
}
Request.setAttribute ("username", user.getUsername ())
Request.setAttribute ("password", user.getPassword ())
System.out.println (user.toString ())
Return new ModelAndView ("succ")
}
/ *
* user login
*
* annotate the configuration, only POST is allowed to submit to this method
*
* @ param username
* @ param password
* @ return
, /
@ RequestMapping (value = "login", method = RequestMethod.POST)
Public ModelAndView login (String username, String password) {
/ / verify that the passed parameters are correct, otherwise return to the login page.
If (this.checkParams (new String [] {username, password})) {
/ / specify the page to be returned as succ.jsp
ModelAndView mav = new ModelAndView ("succ")
/ / return parameters to the page
Mav.addObject ("username", username)
Mav.addObject ("password", password)
System.out
.println ("username=" + username + "password=" + password)
Return mav
}
Return new ModelAndView ("home")
}
/ *
* verify whether the parameter is empty
*
* @ param params
* @ return
, /
Private boolean checkParams (String [] params) {
For (String param: params) {
If (param = = "" | | param = = null | | param.isEmpty ()) {
Return false
}
}
Return true
}
}
two。 [code] web.xml configuration
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen
sixteen
seventeen
eighteen
nineteen
twenty
twenty-one
twenty-two
twenty-three
twenty-four
twenty-five
twenty-six
twenty-seven
twenty-eight
twenty-nine
thirty
thirty-one
thirty-two
thirty-three
thirty-four
thirty-five
thirty-six
thirty-seven
thirty-eight
thirty-nine
forty
forty-one
forty-two
forty-three
forty-four
forty-five
forty-six
Org.springframework.web.context.ContextLoaderListener
ContextConfigLocation
Classpath:*-context.xml
MVC
Org.springframework.web.servlet.DispatcherServlet
ContextConfigLocation
/ WEB-INF/classes/mvc-context.xml
one
MVC
* .do
Index.jsp
3. [code] spring-mvc configuration
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen
sixteen
seventeen
eighteen
nineteen
4. [code] userMapper configuration
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen
sixteen
seventeen
eighteen
nineteen
twenty
twenty-one
twenty-two
twenty-three
twenty-four
twenty-five
twenty-six
twenty-seven
twenty-eight
twenty-nine
thirty
thirty-one
thirty-two
thirty-three
thirty-four
thirty-five
thirty-six
thirty-seven
thirty-eight
thirty-nine
forty
forty-one
forty-two
Select
Id
Username
Password
From user
Username = # {username} and password = # {password}
And id=# {id}
Insert into user (id,username,password) values (# {id}, # {username}, # {password})
Select last_insert_id () as id
Update user
Username=# {username}
Password=# {password}
Where id=# {id}
Delete from user where id=# {id}
Thank you for reading! This is the end of the article on "how to use SpringMVC+myBatis together". I hope the above content can be of some help to you, so that 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.