Step 1, introduce struts2-convention-plugin-2.2.1.jar
Then, modify the configuration file. I modified it in the Struts. properties file:
struts.objectFactory = springstruts.devMode = truestruts.i18n.encoding = UTF-8struts.convention.result.path =/WEB-INF/jsp/struts.convention.package.locators = action,actions,struts,struts2,control,controls,teststruts.convention.action.suffix =Action,Control
The first line is integrated with spring.
The second line is to enable the struts development mode to facilitate debugging.
Row 3, i18n
Row 4: Specify the path of the default view. All view resources are searched from this path.
The fifth line indicates the package name to be searched. I like to name the control class package *. Control, so I added the control package and the test package.
The sixth row specifies the end name of the class file. For example, only classes such as abcaction can be searched by default, and classes such as abccontrol can also be searched now.
Java test code (Part) Project address: http: // localhost: 8080/Photo/
Package COM. lgh. test; import Java. util. list; import Org. apache. struts2.servletactioncontext; import Org. apache. struts2.convention. annotation. namespace; import Org. springframework. beans. factory. annotation. autowired; import Org. springframework. context. annotation. scope; import Org. springframework. stereotype. controller; import Org. apache. struts2.convention. annotation. actions; import Org. apache. struts2.convention. annotation. result; import Org. apache. struts2.convention. annotation. results; import COM. lgh. common. tools. JSON. jsonutil; import COM. lgh. SYS. entity. user; import COM. opensymphony. xwork2.action; @ scope ("prototype") @ controller @ namespace ("/Name") // specify the namespace public class testcontrol implements action {@ autowiredprivate testservice; private user; private string name; private list <user> list; Public String getname () {return name;} public void setname (string name) {This. name = Name;} public user getuser () {return user;} public void setuser (User user) {This. user = user;} // http: // localhost: 8080/Photo/name/test can access this action@org.apache.struts2.convention.annotation.Action (value = "test ", results = {@ result (name = "success", location = "/index. JSP ", type =" Redirect "), @ result (name =" register ", location ="/haha. JSP ", type =" Redirect ")}) Public String test () throws exception {list = testservice. findbysome ("1", user. class); User = testservice. findbysome ("1", user. class ). get (0); name = user. getname (); jsonutil. outtojson (servletactioncontext. getresponse (), user); Return success;} // http: // localhost: 8080/Photo/Haha/register can access this action. Note that the value starts with a slash (/) and indicates the absolute path. The namespace is invalid. @ Org. apache. struts2.convention. annotation. action (value = "/Haha/register", Results = {@ result (name = "success", location = "/index. JSP ", type =" Redirect "), @ result (name =" register ", location = ". /haha. JSP ", type =" Redirect ")}) // after execution, the system jumps to http: // localhost: 8080/Photo/Haha/haha. JSP. /haha. JSP and directly write haha. JSP works the same, but write/haha. after JSP, it will jump to http: // localhost: 8080/Photo/haha. JSP is similar to the absolute path Public String register () throws exception {list = testservice. findbysome ("1", user. class); User = testservice. findbysome ("1", user. class ). get (0); name = user. getname (); // jsonutil. outtojson (servletactioncontext. getresponse (), user); Return "register" ;}@ overridepublic string execute () throws exception {// todo auto-generated method stubreturn NULL ;}}
Download the SSH Integrated Framework. Use myeclipse to import it.
The jar packages of MySQL driver and jackson1.9.11-all are not uploaded. Please search and download by yourself.
Http://download.csdn.net/detail/lgh06/8039749 free points completely free Oh. Poor writing. Sorry ......
Struts2 Convention plug-in trial