分类中使用@property注意点

注意:在在分类中声明@property, 只会生成方法的声明, 不会生成方法的实现和带有_下划线的成员变量;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是基于SSM框架的图书分类管理代码: 1. 实体类 Category.java ```java public class Category { private Integer id; private String name; // getter和setter方法省略 } ``` 2. DAO接口 CategoryMapper.java ```java public interface CategoryMapper { int deleteByPrimaryKey(Integer id); int insert(Category record); int insertSelective(Category record); Category selectByPrimaryKey(Integer id); int updateByPrimaryKeySelective(Category record); int updateByPrimaryKey(Category record); List<Category> selectAll(); } ``` 3. DAO实现类 CategoryMapper.xml ```xml <mapper namespace="com.example.mapper.CategoryMapper"> <resultMap id="categoryMap" type="Category"> <id column="id" property="id" /> <result column="name" property="name" /> </resultMap> <select id="selectAll" resultMap="categoryMap"> SELECT * FROM category </select> <select id="selectByPrimaryKey" resultMap="categoryMap" parameterType="java.lang.Integer"> SELECT * FROM category WHERE id = #{id} </select> <insert id="insert" parameterType="Category" useGeneratedKeys="true" keyProperty="id"> INSERT INTO category(name) VALUES(#{name}) </insert> <update id="updateByPrimaryKeySelective" parameterType="Category"> UPDATE category SET name = #{name} WHERE id = #{id} </update> <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> DELETE FROM category WHERE id = #{id} </delete> </mapper> ``` 4. Service接口 CategoryService.java ```java public interface CategoryService { List<Category> listAll(); Category findById(Integer id); void saveOrUpdate(Category category); void delete(Integer id); } ``` 5. Service实现类 CategoryServiceImpl.java ```java @Service public class CategoryServiceImpl implements CategoryService { @Autowired private CategoryMapper categoryMapper; @Override public List<Category> listAll() { return categoryMapper.selectAll(); } @Override public Category findById(Integer id) { return categoryMapper.selectByPrimaryKey(id); } @Override public void saveOrUpdate(Category category) { if (category.getId() == null) { categoryMapper.insert(category); } else { categoryMapper.updateByPrimaryKeySelective(category); } } @Override public void delete(Integer id) { categoryMapper.deleteByPrimaryKey(id); } } ``` 6. Controller类 CategoryController.java ```java @Controller @RequestMapping("/category") public class CategoryController { @Autowired private CategoryService categoryService; @GetMapping("/list") public String list(Model model) { List<Category> categoryList = categoryService.listAll(); model.addAttribute("categoryList", categoryList); return "category/list"; } @GetMapping("/edit") public String edit(Integer id, Model model) { Category category = null; if (id != null) { category = categoryService.findById(id); } else { category = new Category(); } model.addAttribute("category", category); return "category/edit"; } @PostMapping("/saveOrUpdate") public String saveOrUpdate(Category category) { categoryService.saveOrUpdate(category); return "redirect:/category/list"; } @GetMapping("/delete") public String delete(Integer id) { categoryService.delete(id); return "redirect:/category/list"; } } ``` 以上就是SSM框架图书分类管理的代码,其包括实体类、DAO接口和实现、Service接口和实现、Controller类等。需要注意的是,这里只是示例代码,具体实现可能会有所不同。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值