spring bootをMybatusを使用してEclipseでプロジェクトを作成しています。Parameter(userid)が取得できずにエラーとなっております。myBatisのxmlファイルのparameterTypeなどを変更しまいしたがエラーになってしまい原因がわからず困っております。どなたかわかる方いましたらご教授ください。
java
1//エラーコード 2There was an unexpected error (type=Internal Server Error, status=500). 3nested exception is org.apache.ibatis.binding.BindingException: Parameter 'userid' not found. Available parameters are [arg1, arg0, param1, param2] 4org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'userid' not found. Available parameters are [arg1, arg0, param1, param2]
java
1@Mapper 2public interface ExampleRepository { 3=============================Parameter(userid)が取得できずにエラーになる処理================================= 4 //USER 5 WorkTime findWorkTime(String userid,String workday); 6============================================================================ 7 8 //以下省略 9}
java
1@Service 2public class WorkTimeServiceImpl implements WorkTimeService { 3 4 @Autowired 5 private ExampleRepository mapper; 6=======================//Parameter(userid)が取得できずにエラーになる処理================================ 7 @Override 8 public WorkTime findWorkTime(String userid, String workday) { 9 return mapper.findWorkTime(userid, workday); 10======================================================================================= 11 } 12}
java
1<mapper namespace="com.example.demo.repository.ExampleRepository"> 2 3<!-- =============================================================================================================== --> 4<!-- User --> 5<!-- =============================================================================================================== --> 6 7<resultMap id="UserResultMap" type="com.example.demo.entity.User"> 8<result column="userid" property="userid" jdbcType="VARCHAR" /> 9<result column="password" property="password" jdbcType="VARCHAR" /> 10<result column="role" property="role" jdbcType="VARCHAR" /> 11<result column="firstName" property="firstName" jdbcType="VARCHAR" /> 12<result column="firstName_kana" property="firstName_kana" jdbcType="VARCHAR" /> 13<result column="lastName" property="lastName" jdbcType="VARCHAR" /> 14<result column="lastName_kana" property="lastName_kana" jdbcType="VARCHAR" /> 15<result column="sex" property="sex" jdbcType="VARCHAR" /> 16<result column="birthday" property="birthday" jdbcType="VARCHAR" /> 17<result column="age" property="age" jdbcType="VARCHAR" /> 18<result column="phone" property="phone" jdbcType="VARCHAR" /> 19<result column="addressNomber" property="addressNomber" jdbcType="VARCHAR" /> 20<result column="address01" property="address01" jdbcType="VARCHAR" /> 21<result column="address02" property="address02" jdbcType="VARCHAR" /> 22<result column="joincompany" property="joincompany" jdbcType="VARCHAR" /> 23</resultMap> 24 25<!-- =============================================================================================================== --> 26<!--WorkTime--> 27<!-- =============================================================================================================== --> 28 29<resultMap id="workTimeResultMap" type="com.example.demo.entity.WorkTime" > 30<result column="id" property="id" jdbcType="INTEGER" /> 31<result column="userid" property="userid" jdbcType="VARCHAR" /> 32<result column="workday" property="workday" jdbcType="VARCHAR" /> 33<result column="attendancetimes" property="attendancetimes" jdbcType="VARCHAR" /> 34<result column="startbreaktimes" property="startbreaktimes" jdbcType="VARCHAR" /> 35<result column="endbreaktimes" property="endbreaktimes" jdbcType="VARCHAR" /> 36<result column="absencetimes" property="absencetimes" jdbcType="VARCHAR" /> 37<result column="sumworktimes" property="sumworktimes" jdbcType="VARCHAR" /> 38</resultMap> 39 40 41<!-- =================パラメーター(userid)が取得できずにエラーになる処理============================== --> 42 43<!-- findWorkTime --> 44<select id="findWorkTime" resultMap="workTimeResultMap" > 45SELECT * 46FROM worktimetable 47WHERE userid = #{userid} AND workday = #{workday} 48</select> 49============================================================================ 50 51 52 53<!-- =======================以下は処理ができる====================================== --> 54 55<!-- getWorkList --> 56<select id = "getWorkList" parameterType="java.lang.String" resultMap="workTimeResultMap"> 57SELECT * 58FROM worktimetable 59WHERE userid = #{userid} 60</select> 61 62<!-- registAttendace --> 63<insert id="registAttendace" parameterType="com.example.demo.entity.WorkTime" useGeneratedKeys="true" keyProperty="id"> 64INSERT INTO worktimetable 65(userid,workday,attendancetimes) 66VALUES 67(#{userid},#{workday},#{attendancetimes}) 68</insert> 69 70//以下省略 71 72</mapper>
java
1@Controller 2public class UserController { 3 4 @Autowired 5 private WorkTimeService service; 6 7 private LocalDate localDate = LocalDate.now(); 8 private LocalTime localTime = LocalTime.now(); 9 10 private DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("HH:mm"); 11 private DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd"); 12 13 private String workday =localDate.format(dateFormat); 14 15 private String attendancetimes =localTime.format(timeFormat); 16 private String startbreaktimes =localTime.format(timeFormat); 17 private String endbreaktimes =localTime.format(timeFormat); 18 private String absencetimes =localTime.format(timeFormat); 19 20 21 @RequestMapping("/user") 22 public String user(@AuthenticationPrincipal UserDetailsImpl user, Model model){ 23 model.addAttribute("title","ユーザー画面"); 24 return "user"; 25 } 26 27 @RequestMapping("/user/attendancetimes") 28 public String attendancetimes(@AuthenticationPrincipal UserDetailsImpl user,Model model){ 29 String userid = user.getUsername(); 30 WorkTime workTime = new WorkTime(); 31 32=============================パラメーター(userid)が取得できずにエラーになる処理==================== 33 workTime = service.findWorkTime(userid,workday); 34============================================================================ 35 36 if(workTime.getUserid() != null & workTime.getWorkday() != null) { 37 model.addAttribute("massage","すでに出勤が完了しています。"); 38 return "user"; 39 } 40 workTime.setUserid(userid); 41 workTime.setWorkday(workday); 42 workTime.setAttendancetimes(attendancetimes); 43 service.registAttendance(workTime); 44 model.addAttribute("massage","出勤しました。今日も一日がんばりましょう!!"); 45 return "user"; 46 } 47}
java
1@Data 2public class User implements Serializable{ 3 4 public User() {} 5 6 public User(String userid, String password, String role){ 7 this.userid = userid; 8 this.password = password; 9 this.role = role; 10 } 11 12 private String userid; 13 14 private String password; 15 16 private String role; 17 18 private String firstName; 19 20 private String firstName_kana; 21 22 private String lastName; 23 24 private String lastName_kana; 25 26 private String sex; 27 28 private String birthday; 29 30 private String age; 31 32 private String phone; 33 34 private String addressNomber; 35 36 private String address01; 37 38 private String address02; 39 40 private String joincompany; 41}
java
1@Data 2public class WorkTime { 3 4 private int id; 5 6 private String userid; 7 8 private String workday; 9 10 private String attendancetimes; 11 12 private String startbreaktimes; 13 14 private String endbreaktimes; 15 16 private String absencetimes; 17 18 private String sumworktimes; 19}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/03/29 05:26