加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

使用groovy编写spring的controller(二)

发布时间:2020-12-14 17:07:10 所属栏目:大数据 来源:网络整理
导读:使用groovy编写spring的controller(二) 3、文件清单 web.xml文件: ?xml version="1.0" encoding="UTF-8"? web-app id="cpmis" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLo
使用groovy编写spring的controller(二) 3、文件清单 web.xml文件: <?xml version="1.0" encoding="UTF-8"?> <web-app id="cpmis" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <context-param> ?? <param-name>contextConfigLocation</param-name> ?? <param-value>classpath*:applicationContext.xml</param-value> </context-param> <listener> ?? <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> ?? <servlet-name>sccl</servlet-name> ?? <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> ?? <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> ?? <servlet-name>sccl</servlet-name> ?? <url-pattern>*.do</url-pattern> </servlet-mapping> </web-app> sccl-servlet.xml文件: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> </beans> applicationContext.xml文件: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:lang="http://www.springframework.org/schema/lang" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id="propertyConfigurer" ?? class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" ?? lazy-init="false"> ?? <property name="locations"> ??? <list> ???? <value>classpath*:easygroovy.properties ???? </value> ??? </list> ?? </property> </bean> <bean ?? class="org.springframework.web.servlet.view.InternalResourceViewResolver"> ?? <property name="prefix" value="/" /> ?? <property name="suffix" value=".jsp" /> </bean> <bean id="viewNameTranslator" ?? class="org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator" /> <bean ?? class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" /> <bean id="groovyManager" class="com.sillycat.easygroovy.service.impl.GroovyManagerImpl"> </bean> <lang:groovy id="groovyController" refresh-check-delay="3000" ?? script-source="${groovy.file.path}/groovy/GroovyController.groovy"> ?? <lang:property name="groovyManager" ref="groovyManager" /> </lang:groovy> </beans> easygroovy.properties文件: ############################################### # groovy configuration ############################################### groovy.file.path=file://D:/work/easygroovy GroovyController.groovy文件: package com.sillycat.easygroovy.web; import com.sillycat.easygroovy.model.User; import com.sillycat.easygroovy.service.GroovyManager; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.multiaction.MultiActionController; class GroovyController extends MultiActionController { GroovyManager groovyManager ModelAndView main(HttpServletRequest request,??? HttpServletResponse response) throws Exception { ?? this.groovyManager.echo() ?? User user = this.groovyManager.get(null) ?? user.setUserPassword("222222") ?? System.out.println("controller test2") ?? return new ModelAndView("jsp/view","user",user) } } User.java对象文件: package com.sillycat.easygroovy.model; public class User { private Integer id; private String userName; private String userPassword; ...get和set方法 } GroovyManagerImpl.java文件: package com.sillycat.easygroovy.service.impl; import com.sillycat.easygroovy.model.User; import com.sillycat.easygroovy.service.GroovyManager; public class GroovyManagerImpl implements GroovyManager { public void echo() { ?? System.out.println("success in manager!"); } public User get(Integer id) { ?? User user = new User(); ?? user.setId(Integer.valueOf(1)); ?? user.setUserName("sillycat"); ?? user.setUserPassword("******"); ?? return user; } } 接口文件GroovyManager.java: package com.sillycat.easygroovy.service; import com.sillycat.easygroovy.model.User; public interface GroovyManager { public void echo(); public User get(Integer id); } 问题一: 参考spring2.0.x的例子 E:bookopensourcespringspring-framework-2.0.8samplesshowcasesdynamvc 做出来老是报错 报错: unable to resolve class Property,unable to find class for annotation 也没有特意去深究这个annotation了,直接把groovy文件里面的@Property删除了就好了。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读