jfinal的Route的me.setBaseViewPath("")

本文详细解析了在框架中如何设置和使用视图路径,包括基础路径、控制器级路径及渲染页面时的路径拼接规则,帮助开发者更好地理解和掌握视图展示的底层逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、假如设置基础路径为“first”

me.setBaseViewPath("first")

2、在添加Controller的时候,如果设置viewPath,如下会设置“second”

me.add("/hello",HelloController.class,"second");

如果不设置

//这种情况等效于
//me.add("/hello",HelloController.class,"hello");
me.add("/hello",HelloController.class);

3、在方法中render页面

public class HelloController extends Controller{
	public void index() {
		render("A.html");
	}	

}

此时访问ip/hello,假使为本地测试,即
http://127.0.0.1/hello
将会跳转
webapp/first/second/A.html这个路径

如果第二步的时候没有设置“second”
将会跳转
webapp/first/hello/A.html

好的,首先我们需要创建一个cfg文件来存储可调参数。在你的功能包的cfg文件夹下创建一个名为“params.cfg”的文件,文件内容如下: ``` # Declare the parameters for sensorActuator_node int32 yaw_current_default = 17 int32 depth_current_default = 21 int32 temperature_default = 72 ``` 这里我们定义了三个参数:yaw_current、depth_current和temperature。它们的默认值分别为17、21和72。 接下来,我们需要在sensorActuator_node.py文件中导入dynamic_reconfigure库,以及在代码中添加回调函数和配置服务器。修改后的代码如下: ```python #!/usr/bin/env python import rospy from guidance_navigation_control.msg import controlCommand from guidance_navigation_control.msg import sensorInfo_actuatorStatus from dynamic_reconfigure.server import Server from your_package_name.cfg import paramsConfig yaw_current = 17 depth_current = 21 temperature = 72 def callback(config, level): global yaw_current, depth_current, temperature yaw_current = config.yaw_current_default depth_current = config.depth_current_default temperature = config.temperature_default return config if __name__ == '__main__': rospy.init_node('SENSORS_ACTUATORS') sensorActuator_pub = rospy.Publisher('sensorInfo_actuatorStatus', sensorInfo_actuatorStatus, queue_size=10) rospy.Subscriber('controlCommand', controlCommand, gnc_data) srv = Server(paramsConfig, callback) rate = rospy.Rate(10) final_message = sensorInfo_actuatorStatus() while not rospy.is_shutdown(): final_message.yaw_current = yaw_current final_message.depth_current = depth_current final_message.temperature = temperature final_message.thruster_values[0] = 1600 final_message.thruster_values[1] = 1300 final_message.thruster_values[2] = 1700 final_message.thruster_values[3] = 1200 final_message.thruster_values[4] = 1500 final_message.thruster_values[5] = 1800 final_message.stabilized = True sensorActuator_pub.publish(final_message) rate.sleep() else: exit() ``` 我们在代码中添加了一个名为callback的回调函数,这个函数会在配置服务器中被调用。在这个回调函数中,我们将接收到的参数值赋给全局变量yaw_current、depth_current和temperature。 接下来,我们需要修改sensorActuator_node.py文件的while循环,以便从配置服务器中获取参数值。修改后的代码如下: ```python while not rospy.is_shutdown(): config = srv.get_configuration() final_message.yaw_current = config.yaw_current_default final_message.depth_current = config.depth_current_default final_message.temperature = config.temperature_default final_message.thruster_values[0] = 1600 final_message.thruster_values[1] = 1300 final_message.thruster_values[2] = 1700 final_message.thruster_values[3] = 1200 final_message.thruster_values[4] = 1500 final_message.thruster_values[5] = 1800 final_message.stabilized = True sensorActuator_pub.publish(final_message) rate.sleep() ``` 在这里,我们使用srv.get_configuration()方法从配置服务器中获取参数值,并将它们赋给final_message的对应属性。 最后在你的功能包下的CMakeLists.txt文件中添加以下代码,以便将cfg文件添加到ROS系统中: ``` find_package(catkin REQUIRED COMPONENTS dynamic_reconfigure) generate_dynamic_reconfigure_options(cfg/params.cfg) ``` 现在你可以通过rqt_reconfigure来调整参数值。打开一个新的终端,输入以下命令来启动rqt_reconfigure: ``` rosrun rqt_reconfigure rqt_reconfigure ``` 选择你的sensorActuator_node节点,就可以在界面中看到你定义的三个参数。通过修改参数值,你可以动态地改变final_message的yaw_current、depth_current和temperature属性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值