VO2007 写对应的XML

本文介绍如何使用Boost库在XML中创建和写入注释信息,包括定义folder、大小、路径等,并为两个对象添加属性如名称、坐标。重点在于代码实现和XML结构设置。

bool is_write_xml = true;
    if (is_write_xml == true)
    {
        ptree pt;

        pt.put("annotation.folder", "img");
        pt.put("annotation.size.width", "512");
        pt.put("annotation.size.height", "512");
        pt.put("annotation.path", "");
        pt.put("annotation.segmented", "0");

        for (int index = 0; index < 2; index++)
        {
            ptree pt_object;
            pt_object.put("name", "seting");
            pt_object.put("pose", "Unspecified");
            pt_object.put("bndbox.xmin", "38");
            pt_object.put("bndbox.ymin", "38");
            pt_object.put("bndbox.xmax", "38");
            pt_object.put("bndbox.ymax", "38");

            pt.add_child("annotation.object", pt_object);
        }

        auto settings = boost::property_tree::xml_writer_make_settings<std::string>('\t', 1);
        write_xml("conf.xml", pt, std::locale(), settings);
    }

引用内容中未提及MyBatis-Plus返回实体对应VO的方法。不过通常在MyBatis-Plus中返回实体对应VO可按以下思路操作: ### 1. 定义VO类 首先需要定义与实体对应VO(Value Object)类,VO类用于封装需要展示的数据,它可以只包含实体类的部分属性,也可以包含额外的属性。 ```java public class UserVO { private Long id; private String username; // 可以根据需要添加其他属性和对应的getter、setter方法 public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } } ``` ### 2. 使用Mapper方法返回VO 可以在Mapper接口中定义方法,使用MyBatis-Plus的查询功能返回VO对象。可以使用`@Select`注解或者XML文件来编SQL语句。 #### 使用`@Select`注解 ```java import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Select; public interface UserMapper extends BaseMapper<User> { @Select("SELECT id, username FROM user WHERE id = #{id}") UserVO selectUserVOById(Long id); } ``` #### 使用XML文件 在`UserMapper.xml`文件中编SQL语句: ```xml <mapper namespace="com.example.mapper.UserMapper"> <select id="selectUserVOById" resultType="com.example.vo.UserVO"> SELECT id, username FROM user WHERE id = #{id} </select> </mapper> ``` ### 3. 在Service层调用Mapper方法 在Service层调用Mapper方法获取VO对象。 ```java import com.example.mapper.UserMapper; import com.example.vo.UserVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class UserService { @Autowired private UserMapper userMapper; public UserVO getUserVOById(Long id) { return userMapper.selectUserVOById(id); } } ``` ### 4. 在Controller层返回VO 在Controller层调用Service方法并返回VO对象。 ```java import com.example.service.UserService; import com.example.vo.UserVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; @RestController public class UserController { @Autowired private UserService userService; @GetMapping("/users/{id}") public UserVO getUserVOById(@PathVariable Long id) { return userService.getUserVOById(id); } } ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值