spring,spring mvc,mybatis 常用注解
文章来源:https://www.cnblogs.com/hello-tl/p/9209063.html 0.在spring,soring mvc, mybistis 中的常用注解有一下
<!-- 扫描指定的包中的类上的注解,常用的注解有: -->
<!-- @Controller 声明Action组件 -->
<!-- @Service 声明Service组件 @Service("xxxService") -->
<!-- @Repository 声明Dao组件 -->
<!-- @Component 泛指组件, 当不好归类时. -->
<!-- @RequestMapping("/menu") 请求映射 -->
<!-- @Resource 用于注入,( j2ee提供的 ) 默认按名称装配,@Resource(name="beanName") -->
<!-- @Autowired 用于注入,(spring提供的) 默认按类型装配 -->
<!-- @Transactional( rollbackFor={Exception.class}) 事务管理 -->
<!-- @ResponseBody将内容或对象作为 HTTP 响应正文返回,并调用适合HttpMessageConverter的Adapter转换对象,写入输出流 -->
<!-- @Scope("prototype") 设定bean的作用域 -->
1. @Controller 声明Action组件
package com.web.controller; import org.springframework.stereotype.Controller;
// Controller 声明控制器
@Controller
public class TestController {
/**
* 代码体
*/
}
2. @Service 声明Service组件 @Service("xxxService")
package com.web.service.impl; import org.springframework.stereotype.Service; // 声明service
@Service("testService")
public class TestServiceImpl implements ITestService { }
3. @Repository 声明Dao组件
package com.web.dao; import org.springframework.stereotype.Repository;
// 声明Dao
@Repository
public interface ITestDao {
/**
* 代码体
*/
}
4. @Component 泛指组件, 当不好归类时.
5. @RequestMapping("/menu") 请求映射
package com.web.controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
// 请求映射
@RequestMapping("test")
public class TestController{
// 请求映射
@RequestMapping("index")
public String getProvince(){
return "试图地址";
}
}
6. @Resource 用于注入,( j2ee提供的 ) 默认按名称装配,@Resource(name="beanName")
package com.web.service.impl; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.web.dao.testDao; // 声明service
@Service("testService")
public class TestServiceImpl implements ITestService {
// @Resource 注入
@Resource
private ITestDao testDao;
}
7. @Autowired 用于注入,(spring提供的) 默认按类型装配
package com.web.controller; import org.springframework.stereotype.Controller;
import com.web.service.ITestService; // Controller 声明控制器
@Controller
public class TestController {
// Autowired 用法
@Autowired
private ITestService testService;
}
8. @Transactional( rollbackFor={Exception.class})
package com.web.service.impl; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.web.dao.testDao;
import org.springframework.transaction.annotation.Transactional;
// 声明service
@Service("testService")
public class TestServiceImpl implements ITestService {
// @Resource 注入
@Resource private ITestDao testDao;
@Override
// 添加事务处理
@Transactional( rollbackFor={Exception.class})
public int addTest(TestModel testModel){
return testDao.addtest(testModel);
}
}
9. @ResponseBody将内容或对象作为 HTTP 响应正文返回,并调用适合HttpMessageConverter的Adapter转换对象,写入输出流
package com.web.controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
// 请求映射
@RequestMapping("test")
public class TestController{ // 请求映射
@RequestMapping("index")
// 写入输出
@ResponseBody
public String getProvince(){
return "输入的内容 如 json xml 字符串 等";
}
}
10.@Scope("prototype") 设定bean的作用域
文章来源:https://www.cnblogs.com/hello-tl/p/9209063.html
spring,spring mvc,mybatis 常用注解的更多相关文章
- spring 以及 spring mvc 中常用注解整理
spring 以及 spring mvc 中常用注解整理 @RequestMapping(映射路径) @Autowired(注入 bean 对象) 例如: @Autowired private Bas ...
- spring boot的一些常用注解
spring boot的一些常用注解: 使用@SpringBootApplication注释: 许多Spring Boot开发人员喜欢他们的应用程序使用自动配置,组件扫描,并能够在其“应用程序类”上定 ...
- Solon Web 开发,十四、与Spring、Jsr330的常用注解对比
Solon Web 开发 一.开始 二.开发知识准备 三.打包与运行 四.请求上下文 五.数据访问.事务与缓存应用 六.过滤器.处理.拦截器 七.视图模板与Mvc注解 八.校验.及定制与扩展 九.跨域 ...
- Spring Boot整合MyBatis(非注解版)
Spring Boot整合MyBatis(非注解版),开发时采用的时IDEA,JDK1.8 直接上图: 文件夹不存在,创建一个新的路径文件夹 创建完成目录结构如下: 本人第一步习惯先把需要的包结构创建 ...
- Spring Boot 实战 —— MyBatis(注解版)使用方法
原文链接: Spring Boot 实战 -- MyBatis(注解版)使用方法 简介 MyBatis 官网 是这么介绍它自己的: MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过 ...
- Mybatis 常用注解
Mybatis常用注解对应的目标和标签如表所示: 注解 目标 对应的XML标签 @CacheNamespace 类 <cache> @CacheNamespaceRef 类 <cac ...
- Spring MVC的常用注解(一)
概述 Spring从2.5版本开始引入注解,虽然版本不断变化,但是注解的特性一直被延续下来并不断进行扩展,这里就来记录一下Spring MVC中常用的注解,本文记录@Controller.@Reque ...
- Spring和SpringMVC的常用注解
Spring的部分: 使用注解之前要开启自动扫描功能 其中base-package为需要扫描的包(含子包). <context:component-scan base-package=" ...
- Spring Boot (9) mybatis全注解化
ORM对比图 框架对比 Spring JDBC Spring Data Jpa Mybatis 性能 性能最好 性能最差 居中 代码量 多 少 多 学习成本 低 高 居中 推荐指数 ❤❤❤ ❤❤❤❤❤ ...
随机推荐
- vue 生命周期钩子函数
实例中的生命周期钩子可以分为以下8种情况: beforeCreate: 实例刚被创建,vue所有属性都还不存在 created: 实例创建完成,但$el还不存在 beforeMount:挂载之前 mo ...
- Centos5.11 使用yum源
由于我是用的系统是Centos 5.11以停止更新很多年,故此yum也不能用,找了很多方法,最终yum能稳定的运行在Centos5.11上,下面开始一一讲解步骤: 1:首先更新yum源 地址:http ...
- STP-2-三个选择
1.选择根交换机 2.确定根端口 3.确定指定端口 1.选择根交换机 stp中只有一台交换机能成为根(Root),每台交换机按自己的STP逻辑,先发一个hello称自己为根,如果收到了比自 ...
- 未能载入软件包“WebDriverAgentRunner”,因为它已损坏或丢失必要的资源。
添加 YYCache.framework RoutingHTTPServer.framework
- c/c++学习系列之putchar、getchar、puts、gets的运用
如果您只想取得使用者输入的字元,則可以使用getchar(),它直接取得使用者輸入的字元并传回,如果只想要输出一個字元,則也可以直接使用putchar(),以下是个简单的例子: #include &l ...
- 安卓 使用LruCache 加载图片 遇到的问题
本来 使用listview的时候 加载大图片的时候 会遇到内存溢出而导致崩溃. 但是使用LruCache的时候 原本以为可以 解决这个问题. 但是发现还是出现了内存溢出的情况. 困扰很久 另外, ...
- JS脚本不能执行
这段时间在做前端的动态页面,出了很多问题,因为js平时用的很少,所以花了不少无用功. 其中有两点一定要注意: 1.当js中有语法错误时,js脚本会无法执行. 2.当js脚本中有未定义的变量时,后边的语 ...
- leetcode134 Gas Station
思路: https://leetcode.com/problems/gas-station/discuss/269604/Java-Greedy-thought-process 关键是要想清楚如果从加 ...
- KMP字符串模式匹配详解
KMP字符串模式匹配详解 http://www.cppblog.com/oosky/archive/2006/07/06/9486.html
- android布局带参返回
package com.lxj.lesson2_3ID19; import com.example.lesson2_3_id19.R; import com.lxj.other.AgeActivity ...